mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
21 lines
525 B
JavaScript
21 lines
525 B
JavaScript
import findIndex from 'lodash/findIndex';
|
|
import isPlainObject from 'lodash/isPlainObject';
|
|
|
|
export function removeFromArray (array, element) { // eslint-disable-line import/prefer-default-export, max-len
|
|
let elementIndex;
|
|
|
|
if (isPlainObject(element)) {
|
|
elementIndex = findIndex(array, element);
|
|
} else {
|
|
elementIndex = array.indexOf(element);
|
|
}
|
|
|
|
if (elementIndex !== -1) {
|
|
const removedElement = array[elementIndex];
|
|
array.splice(elementIndex, 1);
|
|
return removedElement;
|
|
}
|
|
|
|
return false;
|
|
}
|