Created
August 12, 2018 21:48
-
-
Save mromanoff/2ae3e0326e68a0ba3ad708a40ae04008 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/cigonet
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
var years = [{ "id": "acura_integra_2001", "title": "2001" }, { "id": "acura_integra_2000", "title": "2000" }, { "id": "acura_integra_1999", "title": "1999" }, { "id": "acura_integra_1998", "title": "1998" }, { "id": "acura_integra_1995", "title": "1995" }, { "id": "acura_integra_1994", "title": "1994" }]; | |
var mmyFromYearId = "acura_integra_1998"; | |
var createToYears = function createToYears(data, id) { | |
var fromIndex = data.findIndex(function (item) { | |
return item.id === id; | |
}); | |
return years.reverse().slice(fromIndex).reverse(); | |
}; | |
console.log(createToYears(years, mmyFromYearId)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const years = [{"id":"acura_integra_2001","title":"2001"},{"id":"acura_integra_2000","title":"2000"},{"id":"acura_integra_1999","title":"1999"},{"id":"acura_integra_1998","title":"1998"},{"id":"acura_integra_1995","title":"1995"},{"id":"acura_integra_1994","title":"1994"}]; | |
let mmyFromYearId = "acura_integra_1998"; | |
const createToYears = function(data, id) { | |
const fromIndex = data.findIndex(item => item.id === id); | |
return years.reverse().slice(fromIndex).reverse(); | |
} | |
console.log(createToYears(years, mmyFromYearId)); | |
</script></body> | |
</html> |
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
"use strict"; | |
var years = [{ "id": "acura_integra_2001", "title": "2001" }, { "id": "acura_integra_2000", "title": "2000" }, { "id": "acura_integra_1999", "title": "1999" }, { "id": "acura_integra_1998", "title": "1998" }, { "id": "acura_integra_1995", "title": "1995" }, { "id": "acura_integra_1994", "title": "1994" }]; | |
var mmyFromYearId = "acura_integra_1998"; | |
var createToYears = function createToYears(data, id) { | |
var fromIndex = data.findIndex(function (item) { | |
return item.id === id; | |
}); | |
return years.reverse().slice(fromIndex).reverse(); | |
}; | |
console.log(createToYears(years, mmyFromYearId)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment