fix: do not break loop while deleting note from topic

This commit is contained in:
thecodrr
2021-07-06 12:12:19 +05:00
parent 33a3fa7968
commit 348726670b
2 changed files with 34 additions and 14 deletions

View File

@@ -0,0 +1,17 @@
export function findItemAndDelete(array, predicate) {
return deleteAtIndex(array, array.findIndex(predicate));
}
export function deleteItem(array, item) {
return deleteAtIndex(array, array.indexOf(item));
}
export function findById(array, id) {
return array.find((item) => item.id === id);
}
function deleteAtIndex(array, index) {
if (index === -1) return false;
array.splice(index, 1);
return true;
}