This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] || []; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
NewerOlder