Skip to content

Instantly share code, notes, and snippets.

@toranb toranb/array-helper.js
Last active Apr 4, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.