Ported sortedarray ( https://github.com/javascript/sorted-array )