Javascript Array isSubsetOf(inputArray)
'use strict';/*from www . j a va2 s . c o m*/ Array.prototype.isSubsetOf = function(inputArray) { var exist = true; for(var i = 0; i < this.length; i++) { if(inputArray.indexOf(this[i]) === -1) { exist = false; } } return exist; };
Array.prototype.isSubsetOf = function(inputArray) { var exists = true; for (var i = 0; i < this.length; i++) { if (inputArray.indexOf(this[i]) === -1) { exists = false;/*w w w.j a v a2s . c om*/ } } return exists; };
// Is Subset Of/*w w w.j av a 2 s. c o 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 both arrays will contain only strings. Array.prototype.isSubsetOf = function(inputArray) { for(var i = 0; i < this.length; i++){ if(!inputArray.includes(this[i])){ return false; } } return true; };
//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 both arrays will //contain only strings. Array.prototype.isSubsetOf = function(inputArray) { //var isSubset = true; for (var i = 0; i < this.length; i++) { var contains = false; for (var j = 0; j < inputArray.length; j++) { if (inputArray[j] === this[i]) { contains = true;//from ww w . ja v a 2 s. co m } } if (!contains) { return false; } } return true; };