Skip to content

add linear search and reverse a string algorithm #4

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions LinearSearch/linearsearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function linearSearch(value, list) {
let found = false;
let position = -1;
let index = 0;

while(!found && index < list.length) {
if(list[index] == value) {
found = true;
position = index;
} else {
index += 1;
}
}
return position;
}
15 changes: 15 additions & 0 deletions bubble-sort/bubbleSort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function bubbleSort(items) {
var length = items.length;
for (var i = (length - 1); i >= 0; i--) {
//Number of passes
for (var j = (length - i); j > 0; j--) {
//Compare the adjacent positions
if (items[j] < items[j - 1]) {
//Swap the numbers
var tmp = items[j];
items[j] = items[j - 1];
items[j - 1] = tmp;
}
}
}
}
6 changes: 6 additions & 0 deletions reversingString/reversestring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function reverse(str) {
let reversedString = str.split("").reverse().join("")
return reversedString
};
reverse('abcd');
// result --> dcba