all files / js/helper/ ArrayHelper.class.js

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                              6314× 6314× 14×   6314×                     287× 287× 6314×   287×          
/**
 * @fileOverview Array Helper Class.
 * @author Simon Gattner <npm@0x38.de>
 * @license MIT
 * @version 1.0.0
 */
class ArrayHelper {
  /**
   * Remove Item from Array
   * @function ArrayHelper.removeItemFromArray
   * @param {array} array to remove a item.
   * @param {string} item to remove.
   * @return {array} the Array with removed item.
   */
  static removeItemFromArray(array, item) {
    const index = array.indexOf(item);
    if (index !== -1) {
      array.splice(index, 1);
    }
    return array;
  }
 
  /**
   * Remove Items from Array
   * @function ArrayHelper.removeItemsFromArray
   * @param {array} array to remove a item.
   * @param {array} items to remove.
   * @return {array} the Array with removed item.
   */
  static removeItemsFromArray(array, items) {
    let newArray = array;
    items.forEach((item) => {
      newArray = ArrayHelper.removeItemFromArray(newArray, item);
    });
    return newArray;
  }
}
 
export const removeItemFromArray = ArrayHelper.removeItemFromArray;
export const removeItemsFromArray = ArrayHelper.removeItemsFromArray;
export default ArrayHelper;