Last active
October 9, 2018 07:06
-
-
Save alichtman/7092463b71e6dbac2be3a3e7aecd1e5b to your computer and use it in GitHub Desktop.
Javascript implementation of Python zip and unpack
This file contains 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
/** | |
* 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