Here you can find the source of isSubsetOf(arr)
/*//from www .java2 s . co m * Make an array method that can return whether or not a context array is a * subset of an input array. To simplify the problem, you can assume that neither * array will contain objects or arrays as elements within them. * * * var a = ['commit','push'] * a.isSubsetOf(['commit','rebase','push','blame']) // true * * NOTE: You should disregard duplicates in the set. * * var b = ['merge','reset','reset'] * * b.isSubsetOf(['reset','merge','add','commit']) // true * * See http://en.wikipedia.org/wiki/Subset for more on the definition of a * subset. */ /* * Extra credit: Make the method work for arrays that contain objects and/or arrays as elements. */ Array.prototype.isSubsetOf = function (arr) { // your code here var subArr = this; var words = {}; for (var i = 0; i < arr.length; i++) { if (!words[arr[i]]) { words[arr[i]] = true; } } for (var i = 0; i < subArr.length; i++) { if (!words[subArr[i]]) { return false; } } return true; }; var a = ['commit','push'] console.log(a.isSubsetOf(['commit','rebase','push','blame'])); // true var b = ['merge','reset','reset'] console.log(b.isSubsetOf(['reset','merge','add','commit'])); // true
Array.prototype.isSubsetOf = function() { var args=arguments[0]; var len=this.length; var i; var counter=0; console.log(args); for(i=0; i<len; i++){ if(args.indexOf(this[i])>=0){ counter++; ...
Array.prototype.isSubsetOf = function(arr) { return isSubsetObjs(this, objectify(arr)); }; var isSubsetObjs = function(arr, obj2) { for (var i = 0; i < arr.length; i++) { if (!obj2.hasOwnProperty(arr[i])) { return false; } return true; ...
Array.prototype.isSubsetOf = function (arr) { for (var i = 0; i < this.length; i++) { if (arr.indexOf(this[i]) === -1) { return false; return true; };
Array.prototype.isSubsetOf = function (arr) { var objectify = function(arr) { var obj = {}; for (var i = 0; i < arr.length; i++) { obj[arr[i]] = true; return obj; }; var obj = objectify(arr); ...
Array.prototype.isSubsetOf = function (arr) { let result = 0; for (let i = 0; i < this.length; i += 1) { for (let p = 0; p < arr.length; p += 1) { if (this[i] === arr[p]) { result += 1; break; if (i + 1 !== result) { return false; return true; }; const b = ['merge','reset','reset'] console.log(b.isSubsetOf(['reset','merge','add','commit'])); const a = ['commit','push','blame']; console.log(a.isSubsetOf(['commit','rebase','push','blame']));
Array.prototype.isSubsetOf = function (arr) { var objectify = function (arr) { var obj = {}; for (var i = 0; i < arr.length; i++) { obj[arr[i]] = true; return obj; }; var obj = objectify(arr); ...
Array.prototype.isSubsetOf = function(array) { return this.reduce(function (acc, val) { if (acc) { return array.includes(val); return false; }, true) };
Array.prototype.isSubsetOf = function(array) { for(var i = 0; i < this.length; i++){ if(array.indexOf(this[i])===-1){ return false return true; };
Array.prototype.isSubsetOf = function(array) { var isSubset = true; if(this.forEach(function(element){ if(!array.includes(element)){ isSubset = false; })); return isSubset; }; ...