Snippet format update

To match the starter (for the migration)
This commit is contained in:
Angelos Chalaris
2019-08-13 10:29:12 +03:00
parent a5164f392a
commit 611729214a
381 changed files with 1951 additions and 1989 deletions

View File

@@ -1,4 +1,7 @@
### binarySearch
---
title: binarySearch
tags: algorithm,beginner
---
Use recursion. Similar to `Array.prototype.indexOf()` that finds the index of a value within an array.
The difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or `Array.prototype.indexOf()`.
@@ -21,4 +24,4 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
```js
binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6); // 2
binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1
```
```