Skip to content

Instantly share code, notes, and snippets.

View hzhu's full-sized avatar
🍵
building matcha.xyz

henryzhu.eth hzhu

🍵
building matcha.xyz
View GitHub Profile
@hzhu
hzhu / .js
Last active September 24, 2015 21:56
Data Transformation
var x = [ {node: "ip2", app: "dbsyncer", containerId: "1234"},
{node: "ip2", app: "logforwa", containerId: "3423"},
{node: "ip4", app: "dbsyncer", containerId: "2213"},
{node: "ip4", app: "logforwa", containerId: "3434"} ]
var newObj = {};
x.forEach(function (item) {
newObj[item.node] = newObj[item.node] || [];
@hzhu
hzhu / reduce.js
Last active May 2, 2019 14:15
Reduce ES5 / ES6
// reduce boils down a list of values into a single value
// var callback = function (previousValue, currentValue, index, array) {
// return previousValue + currentValue
// }
// [].reduce(callback, initialValue)
//
// Reduce invokes the callback on each item in the array.
// On the first invocation, the first item is passed to the callback as currentValue.
// and the initialValue is passed as the previousValue.
// The returned value of that is then passed into the next invocation of the second item as previousValue.
@hzhu
hzhu / LOYAL3-hearts-II.markdown
Created November 12, 2013 06:07
A Pen by Henry Zhu.