1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 16:45:16 +00:00

Automatically clean up old entries

This commit is contained in:
2020-03-25 18:01:07 +01:00
parent 7a1a26e919
commit ea99796edf
2 changed files with 24 additions and 3 deletions

View File

@ -21,4 +21,20 @@ export function findKey(object: Object, value: any): string {
}
return null;
}
}
/**
* Remove all the entries of an array that meets a certain condition
*
* @param array Input array
* @param callback Callback function to call on each element
* of the array
*/
export function removeWhere<T>(array: Array<T>, callback: (el: T) => boolean) {
var i = array.length;
while (i--) {
if (callback(array[i])) {
array.splice(i, 1);
}
}
};