Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2016 19:23
Show Gist options
  • Select an option

  • Save anonymous/ab45d53581de1439eacb to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/ab45d53581de1439eacb to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/wavofodoza
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//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)
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">
//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)
}</script></body>
</html>
//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