-
-
Save 03difoha/23e5ad9a2ecdc3f091a017b80f168730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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