Any JavaScript folks here? I'm a bit confused abou...
# random
f
Any JavaScript folks here? I'm a bit confused about finding the time complexity of the below function.
Copy code
function containCommonItems(firstArray, secondArray) {
        return firstArray.some(item => secondArray.includes(item))
    }
I'm not exactly sure what happens inside the include method. So I'm assuming It's a loop, and the time complexity of the above function is O(n * m). But I have heard some other guys saying it O(n+m). Could someone clarify this.?
w
You should first read about
some
method for Arrays
f
Thanks for your reply @wonderful-dusk-20983. I know how it works, but I have no idea how they implemented some and include methods. So how could I say the time complexity of a function uses those methods. Here I need your help, guys.
d
@fast-doctor-62382 I should be O (n * m) to my knowledge too. It (
includes
) uses linear search. https://tc39.es/ecma262/#sec-array.prototype.includes
👍 1
f
Thanks @dazzling-autumn-14365
d
@fast-doctor-62382 https://www.geeksforgeeks.org/how-to-find-if-two-arrays-contain-any-common-item-in-javascript/ Geeks for geeks also mentions O(m+n). See 3rd. But IDK how.
f
The author hasn't mentioned the complexity of the 3rd method. But sure it's not Brute-force