26 lines
No EOL
505 B
JavaScript
26 lines
No EOL
505 B
JavaScript
/**
|
|
* @param {*} item
|
|
* @param {*[]} array
|
|
*/
|
|
export function removeFromArray(item, array) {
|
|
const index = array.indexOf(item);
|
|
if (index !== -1) {
|
|
array.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {*[]} array
|
|
* @returns {*}
|
|
*/
|
|
export function randomFromArray(array) {
|
|
return array[Math.floor(Math.random() * array.length)];
|
|
}
|
|
|
|
/**
|
|
* @param {*[]} array
|
|
* @returns {*[]}
|
|
*/
|
|
export function removeDuplicatesFromArray(array) {
|
|
return array.filter((item, index) => array.indexOf(item) === index);
|
|
} |