fix(curriculum): editable regions in workshop binary search js (#67793)

This commit is contained in:
Aditya Singh 2026-06-03 22:54:23 +05:30 committed by GitHub
parent 2e40de1662
commit 58df87f2f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 29 additions and 18 deletions

View File

@ -34,6 +34,7 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
--fcc-editable-region--
--fcc-editable-region--

View File

@ -33,9 +33,10 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
--fcc-editable-region--
--fcc-editable-region--
}
}

View File

@ -31,6 +31,7 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
--fcc-editable-region--

View File

@ -29,6 +29,7 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];

View File

@ -40,10 +40,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
--fcc-editable-region--
--fcc-editable-region--

View File

@ -39,10 +39,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
}

View File

@ -40,10 +40,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
}

View File

@ -33,13 +33,15 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
--fcc-editable-region--
if (value === valueAtMiddle) {
return pathToTarget;
--fcc-editable-region--
}
--fcc-editable-region--
break;

View File

@ -28,19 +28,19 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
} else if (value > valueAtMiddle) {
--fcc-editable-region--
--fcc-editable-region--
}
break;
}
return [];

View File

@ -31,21 +31,20 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
} else if (value > valueAtMiddle) {
low = mid + 1;
}
--fcc-editable-region--
}
break;
--fcc-editable-region--
}
return [];
}

View File

@ -33,11 +33,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
} else if (value > valueAtMiddle) {

View File

@ -29,11 +29,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return pathToTarget;
} else if (value > valueAtMiddle) {
@ -43,7 +44,7 @@ function binarySearch(searchList, value) {
}
}
--fcc-editable-region--
return [];
return [];
--fcc-editable-region--
}

View File

@ -33,16 +33,16 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
--fcc-editable-region--
return pathToTarget;
--fcc-editable-region--
} else if (value > valueAtMiddle) {
low = mid + 1;
} else {
@ -50,7 +50,6 @@ function binarySearch(searchList, value) {
}
}
return [[], "Value not found"];
}
console.log(binarySearch([1, 2, 3, 4, 5], 3));
@ -65,12 +64,12 @@ function binarySearch(searchList, value) {
let pathToTarget = [];
let low = 0;
let high = searchList.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let valueAtMiddle = searchList[mid];
pathToTarget.push(valueAtMiddle);
if (value === valueAtMiddle) {
return [pathToTarget, `Value found at index ${mid}`];
} else if (value > valueAtMiddle) {
@ -79,7 +78,6 @@ function binarySearch(searchList, value) {
high = mid - 1;
}
}
return [[], "Value not found"];
}