const arr = new Array(1000000) for(let i = 0; i < arr.length; i++) { arr[i] = i + 1; }
Initializing...
function numberSerch(arr, el) { for (let i = 0; i < arr.length; i++) { if (arr[i] === el) { return i; } } return -1; } const el = Math.floor(Math.random() * arr.length) numberSerch(arr, el)
function searchElement(arr, el) { let left = -1; let right = arr.length; while (right - left > 1) { const mid = Math.floor((left + right) / 2); if (arr[mid] === el) { return mid; } if (arr[mid] > el) { right = mid; } else { left = mid; } } return -1; } const el = Math.floor(Math.random() * arr.length) numberSerch(arr, el)
You can edit these tests or add more tests to this page by appending /edit to the URL.