Skip to content

Instantly share code, notes, and snippets.

@toranb
Last active April 4, 2016 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toranb/b661b53f9ab277ef8d4041cebe770414 to your computer and use it in GitHub Desktop.
Save toranb/b661b53f9ab277ef8d4041cebe770414 to your computer and use it in GitHub Desktop.
a simple array helper to return a new collection of data
export function uniq(first, second) {
let ret = [];
const collection = first.concat(second);
collection.forEach((k) => {
var index = ret.findIndex((item) => item.id === k.id);
if (index === -1) {
ret.push(k);
}else{
ret.replace(index, 1, k);
}
});
return ret;
}
export function remove(collection, id) {
var index = collection.findIndex((item) => item.id === id);
return [
...collection.slice(0, index),
...collection.slice(index + 1)
];
}
//100% certain someone could do this better with lodash :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment