I have an array of objects that I know is sorted by one of the object properties. I want to look in the array for the object with that property equalling a specific value, so I do this:
arrOfObjects.find((obj) => obj.property === value)
However, this is an O(n) operation for an unsorted array, but O(log n) using binary search on sorted arrays.
Is there any way to tell JavaScript my array is sorted when doing a .find(), or do I have to manually implement a binary search?
findthat information.arrOfObjectsaMap, keyed byobj.property. Then you get constant access.findisO(n)O(n)so you've always got that time complexity, might just stick with.findunless there's asortedflag after a sorting method is called.