-
-
Save teebu/61813199fc25ad80656e to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/wavofodoza
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
//console.log(stringDateToEpoch("2016-01-31T21:52:02.607Z")) | |
var obj = { "rank_history": [ | |
{"date": "2016-02-17T04:27:16.773Z","rank": 121}, | |
{"date": "2016-02-15T05:37:16.773Z","rank": 122}, | |
[1455763092,153], | |
[1455761092,154], | |
{"date": "2016-02-14T02:27:16.773Z","rank": 125}, | |
[1455781509,156] | |
] | |
} | |
var rankHistory = obj.rank_history // array | |
var new_format = [] | |
new_format = _.map(rankHistory, function(value,key){ | |
if (value.date && value.rank){ | |
return ([stringDateToEpoch(value.date),value.rank]) | |
} else { | |
return ([value[0],value[1]]) | |
} | |
//console.log(key,value) | |
}) | |
//rankHistory = new_format | |
console.log(new_format) | |
function stringDateToEpoch(string){ | |
return Math.round((new Date(string)).getTime() / 1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment