Skip to content

Instantly share code, notes, and snippets.

@teebu
Forked from anonymous/index.html
Created February 18, 2016 19:23
Show Gist options
  • Save teebu/61813199fc25ad80656e to your computer and use it in GitHub Desktop.
Save teebu/61813199fc25ad80656e to your computer and use it in GitHub Desktop.
//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