Skip to content

Instantly share code, notes, and snippets.

@mhmdAljefri
Last active March 13, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhmdAljefri/e938fa790cfe55645e3654663ec6549d to your computer and use it in GitHub Desktop.
Save mhmdAljefri/e938fa790cfe55645e3654663ec6549d to your computer and use it in GitHub Desktop.
function isSubset(array1, array2) {
  const filterdArray2Set = [...new Set(array2)]; // return uniq array

  let subset = false
  filterdArray2Set.forEach((item) => {
    subset = array1.includes(item)
    if (!subset) return;
  });
  
  return subset
}

isSubset([A,B,C,D,E], [A,E,D])

O (n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment