Skip to content

Instantly share code, notes, and snippets.

@03difoha
Created September 19, 2019 03:09
Show Gist options
  • Save 03difoha/23e5ad9a2ecdc3f091a017b80f168730 to your computer and use it in GitHub Desktop.
Save 03difoha/23e5ad9a2ecdc3f091a017b80f168730 to your computer and use it in GitHub Desktop.
function isSubset(list1, list2) {
let list2 = [...new Set(list2)];
let confirmed = 0
for (var l of list2) {
if (list1.includes(l)) {
confirmed++
}
}
return confirmed == list2.length
}
// computational complexity is O(N2) because iterations are multiplied by the length of list2, and also by List1 when
// we use includes() which is a linear search function
// note creating a set of list2 removes unnessasary items and could improve effeciency, especially is list2 was very large
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment