Skip to content

Instantly share code, notes, and snippets.

@alichtman
Last active October 9, 2018 07:06
Show Gist options
  • Save alichtman/7092463b71e6dbac2be3a3e7aecd1e5b to your computer and use it in GitHub Desktop.
Save alichtman/7092463b71e6dbac2be3a3e7aecd1e5b to your computer and use it in GitHub Desktop.
Javascript implementation of Python zip and unpack
/**
* Takes three arrays and zips them into a list of lists like this:
*
* [1,2,3]
* [a,b,c] -> [ [1,a,!], [2,b,@], [3,c,#] ]
* [!,@,#]
*/
function zipThreeArrays(a, b, c) {
let zipped = [];
for (var i = 0; i < a.length; i++) {
zipped.push([a[i], b[i], c[i]]);
}
return zipped;
}
// Takes dictionary with key -> list pairs and returns a list of lists.
function unpackData(dict) {
var listOfIndicatorData = [];
Object.keys(dict["data"]).forEach(function(key) {
listOfIndicatorData.push([key, dict["data"][key]["value"], dict["data"][key]["signal"]]);
});
return listOfIndicatorData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment