Nodejs Array Subset isSubsetOf(inputArray)

Here you can find the source of isSubsetOf(inputArray)

Method Source Code

//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 .j  av  a  2  s .c o m*/
      }
    }
    if (!contains) {
      return false;
    }
  }
  return true;
};

Related

  1. isSubsetOf(comparisonArray)
    Array.prototype.isSubsetOf = function(comparisonArray) {
      for (var i = 0; i < this.length; i++) {
        if (comparisonArray.indexOf(this[i]) === -1) {
          return false;
      return true;
    };
    
  2. isSubsetOf(input)
    Array.prototype.isSubsetOf = function(input) {
      var isSub = true;
      this.forEach(function (el) {
        if (!input.includes(el)) {
          isSub = false;
      });
      return isSub;
    };
    ...
    
  3. isSubsetOf(input)
    Array.prototype.isSubsetOf = function(input){
      let result = true;
      this.forEach(item => input.indexOf(item) !== -1 ? result = result && true : result = false);
      return result;
    
  4. isSubsetOf(input)
    Array.prototype.isSubsetOf = function(input) {
      var freq = {};
      for (var i = 0; i < this.length; i++) {
        freq[this[i]] = 1;
      for (var j = 0; j < input.length; j++) {
        if (freq[input[j]]) {
          delete freq[input[j]];
      return Object.keys(freq).length === 0;
    };
    
  5. isSubsetOf(inputArray)
    Array.prototype.isSubsetOf = function(inputArray) {
      var exists = true;
      for (var i = 0; i < this.length; i++) {
        if (inputArray.indexOf(this[i]) === -1) {
          exists = false;
      return exists;
    };
    ...
    
  6. isSubsetOf(matchArr)
    Array.prototype.isSubsetOf = function (matchArr) {
      var arr = this;
      for (var i = 0; i < arr.length; i++) {
        if (matchArr.indexOf(arr[i]) === -1 && typeof arr[i] !== 'object') {
          return false;
      return true;
    };
    ...
    
  7. isSubsetOf(subset)
    'use strict';
    Array.prototype.isSubsetOf = function(subset){
      var arr = this;
    };
    
  8. isSubsetOfarray()
    Array.prototype.isSubsetOf = array => {
      let hash = {};
      let result = true;
      array.forEach(item => {
        hash.item ? hash.item++ : hash.item = 0;
      });
      this.forEach(item => {
        hash.item ? hash.item++ : result = false;
      });
    ...