Nodejs Utililty Methods Array Subset

List of utility methods to do Array Subset

Description

The list of methods to do Array Subset are organized into topic(s).

Method

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;
};
...
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;
...
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 );
...
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;
};
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;
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;
...
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;
};
...
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;
};
isSubsetOf(input)
Array.prototype.isSubsetOf = function(input) {
  var isSub = true;
  this.forEach(function (el) {
    if (!input.includes(el)) {
      isSub = false;
  });
  return isSub;
};
...
isSubsetOf(input)
Array.prototype.isSubsetOf = function(input){
  let result = true;
  this.forEach(item => input.indexOf(item) !== -1 ? result = result && true : result = false);
  return result;