mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-05 21:04:28 +08:00
fix(curriculum): editable regions in workshop binary search js (#67793)
This commit is contained in:
parent
2e40de1662
commit
58df87f2f4
@ -34,6 +34,7 @@ function binarySearch(searchList, value) {
|
||||
let pathToTarget = [];
|
||||
let low = 0;
|
||||
let high = searchList.length - 1;
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -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--
|
||||
}
|
||||
}
|
||||
|
||||
@ -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--
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -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--
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 [];
|
||||
|
||||
@ -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 [];
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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--
|
||||
}
|
||||
|
||||
|
||||
@ -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"];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user