Nodejs Array Subset isSubsetOf(array)

Here you can find the source of isSubsetOf(array)

Method Source Code

Array.prototype.isSubsetOf = function(array) {
  var isSubset = true;

  if(this.forEach(function(element){
    if(!array.includes(element)){
      isSubset = false;/*from ww  w.ja v a2  s .  c om*/
    }
  }));

  return isSubset;
};

Related

  1. isSubsetOf(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']));
    
  2. isSubsetOf(arr)
    Array.prototype.isSubsetOf = function (arr) {
      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++) {
    ...
    
  3. isSubsetOf(arr)
    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);
    ...
    
  4. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      return this.reduce(function (acc, val) {
        if (acc) {
          return array.includes(val);
        return false;
      }, true)
    };
    
  5. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      for(var i = 0; i < this.length; i++){
        if(array.indexOf(this[i])===-1){
          return false
      return true;
    };
    
  6. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      var result = true;
      for (var i = 0; i < this.length; i ++) {
        if(array.indexOf(this[i]) === -1) {
          result = false;
      return result;
    };
    ...
    
  7. isSubsetOf(array)
    Array.prototype.isSubsetOf = function(array) {
      var arr = this;
      var obj = {};
      for(var i=0; i<array.length; i++) {
        obj[array[i]] = true; 
      for(var i=0; i<arr.length; i++) {
        if(!(arr[i] in obj)) {
          return false;
    ...
    
  8. isSubsetOf(array)
    Array.prototype.isSubsetOf = function (array) {
      var subset    = this;
      var subsetLen = subset.length;
      var supersetLen = array.length;
      var first, found;
      if ( subsetLen > supersetLen ) return false;
      if ( subsetLen === 0 && supersetLen >= 0 ) return true;
      first = subset[0];
      found = array.indexOf( first );
    ...
    
  9. 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;
    };