List of utility methods to do Array Check
is(that)Array.prototype.is = function(that) { var i, len, ok = true; for (i = 0, len = this.length; i < len && ok; i++) { if (this[i] instanceof Array && that[i] instanceof Array) { ok = this[i].is(that[i]); } else { ok = this[i] === that[i]; return ok; }; | |
isAllNegative()function maxSubArray (array) { var maxSoFar = 0, maxSum = 0; if (array.isAllNegative()) { var maxNum = Number.NEGATIVE_INFINITY; for (var j = 0, jLen = array.length; j < jLen; j++) { if (array[j] > maxNum) { maxNum = array[j] return maxNum; for (var i = 0, len = array.length; i < len; i++) { maxSoFar += array[i]; if (maxSoFar < 0) { maxSoFar = 0; else if (maxSoFar > maxSum) { maxSum = maxSoFar; return maxSum; Array.prototype.isAllNegative = function () { for (var i = 0, len = this.length; i < len; i++) { if (this[i] >= 0) { return false; return true; var myArray = [-100,-2,-3,-4,-105,-104]; maxSubArray(myArray); | |
isArray(obj)Array.isArray = Array.isArray || function (obj) { return {}.call(obj) === '[object Array]'; }; | |
isBlank()function proxy(func, context, args) { return function () { return func.apply(context, args); Array.prototype.isBlank = function () { return !this.length; }; | |
isCharPresent(charSearch)Array.prototype.isCharPresent = function(charSearch) { var arr = this; var result = []; var testingStr = ''; if (charSearch.length > 1) { return "You're searching for more than one char"; for (var i = 0; i < this.length; i++) { if (arr[i].indexOf(charSearch) === -1) { ... | |
isDefined(key)Array.prototype.isDefined = function (key) { return this.filter(c => { if (key) return c[key]; return !!c; }); | |
isDistinct()Array.prototype.isDistinct = function() { this.sort(); for (var i = 1; i < this.length; i++) { if (this[i - 1] == this[i]) return false; return true; }; | |
isInt()Array.prototype.isInt = function (){ return this.filter(function(n){ return (typeof(n) === 'number') && (n%1 === 0)}) }; Array.prototype.even = function (){ return this.isInt().filter(function(n){ return n%2 === 0}) }; Array.prototype.odd = function (){ return this.isInt().filter(function(n){ return n%2 !== 0}) }; ... | |
isLastIndex(index)Array.prototype.isLastIndex = function(index) { return index == (this.length - 1); | |
isMember(b)Array.prototype.isMember = function (b) { return this.some(function (i) { return this == i }, b); |