Binary search algorithm
npm install binary-algorithm-searchbash
import { search } from 'binary-algorithm-search'
search([1, 2, 3, 4, 5], 3); // expected return: 2
`
Signature:
`bash
search(list: number[], target: number): number
`
Params:
| Param | Value |
| ------------- | ------------- |
| list | Array of sorted numbers |
| target | Number to be found |
| return | Index of the target value. |
Sort
The search method assumes that the array passed as the first argument is already sorted for performance reasons. However, if you need to sort the array before using the search method, you can simply import the sort method and pass the list to it:
`bash
import { sort } from 'binary-algorithm-search'
sort([5, 4, 3, 2, 1]); // expected return: [1, 2, 3, 4, 5]
`
Signature:
`bash
sort(list: number[]): number[]
``
Made with ❤️ by Davy de Souza