Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 002_search linearSearch/binarySearch(feature-004_algorithm_002_search) #3

Merged
merged 4 commits into from Mar 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions 004_algorithm/002_search.js
@@ -1,4 +1,3 @@

/**
* 2.3.1 リニアサーチ
*
Expand All @@ -11,7 +10,15 @@
* [5, 3, 2, 1], 6 => -1
*/

function linearSearch (array, target) {
function linearSearch(array, target) {
let index = -1;

for (let i = 0; i < array.length; i++) {
if (array[i] === target) {
index = i;
}
}
return index;
}

yko-git marked this conversation as resolved.
Show resolved Hide resolved
/**
Expand All @@ -24,10 +31,12 @@ function linearSearch (array, target) {
* [1, 2, 3, 4] 5 => -1
*/

function binarySearch (array, target) {
function binarySearch(array, target) {
let arrayLength = array.length / 2;
console.log(arrayLength);
}

module.exports = {
linearSearch,
binarySearch
}
binarySearch,
};