Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
on June 12, 2015
|
parent
|
context
|
favorite
| on:
ES6 in Depth – Symbols
[deleted]
teechap
on June 12, 2015
[–]
I think the only way .indexOf could be faster than linear is if the array is sorted...
on June 12, 2015
|
parent
|
next
[3 more]
[deleted]
teechap
on June 12, 2015
|
root
|
parent
|
next
[–]
Linear definitely isn't faster than binary search. To answer your original question, .indexOf is definitely implemented as linear search in JavaScript
Demiurge
on June 12, 2015
|
root
|
parent
|
next
[–]
Ok, it makes sense to me now. indexOf is used on mostly unsorted things, like strings. So, I guess the original problem might use a sorted array, or an object instead of an array, since I think the object keys are sorted and looked up pretty fast.
Demiurge
on June 12, 2015
|
parent
|
prev
[–]
I got it, it didn't even occur to me the array would be unsorted.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: