From db092d808e227fb2af85b7d2a463ec6608fc5cfa Mon Sep 17 00:00:00 2001 From: King Date: Fri, 5 Jan 2018 11:29:14 -0500 Subject: [PATCH] update description --- snippets/binarySearch.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/binarySearch.md b/snippets/binarySearch.md index c34ba397e..9f64191ef 100644 --- a/snippets/binarySearch.md +++ b/snippets/binarySearch.md @@ -1,8 +1,8 @@ ### binarySearch -Use recursion. Similar to `Array.indexOf()` that finds the index of a value within an array. The two differences being -1. Operation only works with sorted arrays -2. Offers a major performance boost when compared to a linear search or `Array.indexOf()` +Use recursion. Similar to `Array.indexOf()` that finds the index of a value within an array. The difference being 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.indexOf()` + +Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half. Repeatedly recurse until the value is found which is the mid or you've recursed to a point that is greater than the length which means the value doesn't exist and return `-1`. ```js const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {