Skip to content

Instantly share code, notes, and snippets.

@bryzettler
Created June 1, 2017 04:50
Show Gist options
  • Save bryzettler/e6f3a2090ca5b247328718bc666b3355 to your computer and use it in GitHub Desktop.
Save bryzettler/e6f3a2090ca5b247328718bc666b3355 to your computer and use it in GitHub Desktop.
const records = [
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"},
{ title: "Rocket to Russia", artist: "Ramones", type: "LP", lengthSec: 1906, released: "1977"},
{ title: "London Calling", artist: "The Clash", type: "LP", lengthSec: 3903, released: "1979"},
{ title: "Ramones", artist: "Ramones", type: "LP", lengthSec: 1755, released: "1976"},
...etc
];
const removeIndexes = [1, 2];
records.reduceRight((acc, item, idx) => {
// index exists in removeIndexes
// lets remove/filter it out
if(removeIndexes.includes(idx)) return acc;
// otherwise add it to the final result
return [
...acc,
record,
];
}, []);
/*
=> [
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"},
{ title: "Ramones", artist: "Ramones", type: "LP", lengthSec: 1755, released: "1976"},
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment