UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

40 lines (38 loc) 1.02 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Array utils. @namespace este.array */ goog.provide('este.array'); goog.require('goog.array'); /** Removes all values that satisfies the given condition. @param {IArrayLike} arr @param {Function} f The function to call for every element. This function takes 3 arguments (the element, the index and the array) and should return a boolean. @param {Object=} obj An optional "this" context for the function. @return {boolean} True if an element was removed. */ este.array.removeAllIf = function(arr, f, obj) { var idx, removed; idx = arr.length; removed = false; while (idx--) { if (!f.call(obj, arr[idx], idx, arr)) { continue; } arr.splice(idx, 1); removed = true; } return removed; }; /** Removes undefined values from array. @param {IArrayLike} arr */ este.array.removeUndefined = function(arr) { return este.array.removeAllIf(arr, function(item) { return item === void 0; }); };