refactor: cleanup tags related code

This commit is contained in:
thecodrr
2021-07-12 13:48:48 +05:00
parent 11aea82368
commit cc93e4f1c9
3 changed files with 28 additions and 34 deletions

View File

@@ -2,6 +2,13 @@ export function findItemAndDelete(array, predicate) {
return deleteAtIndex(array, array.findIndex(predicate));
}
export function addItem(array, item) {
const index = array.indexOf(item);
if (index > -1) return false;
array.push(item);
return true;
}
export function deleteItem(array, item) {
return deleteAtIndex(array, array.indexOf(item));
}
@@ -16,6 +23,10 @@ export function findById(array, id) {
return array.find((item) => item.id === id);
}
export function hasItem(array, item) {
return array.indexOf(item) > -1;
}
function deleteAtIndex(array, index) {
if (index === -1) return false;
array.splice(index, 1);