Nodejs Array Subset isSubsetOf(input)

Here you can find the source of isSubsetOf(input)

Method Source Code

// determines if an array is a subset of another array
Array.prototype.isSubsetOf = function(input) {
  var isSub = true;

  this.forEach(function (el) {
    if (!input.includes(el)) {
      isSub = false;/*from w w  w .  jav  a  2 s  .  c  o m*/
    }
  });
  return isSub;
};

Related

  1. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      var subArray = this;
      var map = {};
      for(var i=0;i<subArray.length;i++){
        if(!map[subArray[i]]){
          if(array.indexOf(subArray[i]) === -1){
            return false;
        map[subArray[i]] = true;
      return true;
    };
    
  2. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      function arrayContains(array, item) {
        for (var i = 0; i < array.length; i++) {
          if (array[i] === item) {
            return true;
        return false;
      for (var i = 0; i < this.length; i++) {
        if (!arrayContains(array, this[i])) {
          return false;
      return true;
    
  3. isSubsetOf(array)
    var a = ['commit', 'push'];
    var b = ['merge', 'reset', 'reset'];
    Array.prototype.isSubsetOf = function (array) {
      for (var i = 0; i < this.length; i++) {
        if (array.indexOf(this[i]) === -1) {
          return false;
      return true;
    ...
    
  4. isSubsetOf(bigArray)
    Array.prototype.isSubsetOf = function(bigArray) {
      var uniqueSub = this.unique();
      var uniqueBig = bigArray.unique();
      var status = true;
      this.forEach(function(item) {
        if(bigArray.indexOf(item) === -1) status = false;
      });
      return status;
    };
    ...
    
  5. 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;
    };
    
  6. isSubsetOf(input)
    Array.prototype.isSubsetOf = function(input){
      let result = true;
      this.forEach(item => input.indexOf(item) !== -1 ? result = result && true : result = false);
      return result;
    
  7. 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;
    };
    
  8. 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;
    };
    ...
    
  9. isSubsetOf(inputArray)
    Array.prototype.isSubsetOf = function(inputArray) {
      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;
        if (!contains) {
    ...