Created
October 1, 2018 03:33
-
-
Save hillal20/7a4d21b97565f5c518a95027f3fa1da1 to your computer and use it in GitHub Desktop.
PeriodicLazyCoordinates created by hillal20 - https://repl.it/@hillal20/PeriodicLazyCoordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = [1,8,4,5,9] | |
function bs(l,h,arr,key){ | |
let sArr = arr.sort((a,b)=>{ | |
return a > b | |
}) | |
let middle = Math.floor((l+h+1/2)) | |
if( l === h ){ | |
if (sArr[l] === key){ | |
return true | |
} | |
} | |
else { | |
if (sArr[middle]=== key){ | |
return true | |
} | |
else if (key < sArr[middle]){ | |
return bs(l, middle-1,sArr,key) | |
} | |
else if (key > sArr[middle]){ | |
return bs(middle + 1, h ,sArr,key) | |
} | |
return false | |
} | |
} | |
console.log(bs(0,a.length-1,a,8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment