Algorithms and Data Structures · Junior · Question 9 of 75

Why is set.has(x) usually faster than arr.includes(x) for large collections?

Explanation

Set (and Map) are implemented with hash tables: the value's hash points almost directly to where it is stored. Set is not sorted and can store values of any type.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 9

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz