Skip to content

feat: implement problem solving #88

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

Merged
merged 2 commits into from
Jun 14, 2023
Merged
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
28 changes: 28 additions & 0 deletions src/code-challenges/bubble-sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 001: Bubble Sort: is based on the idea of repeatedly comparing pairs of adjacent elements and
* then swapping their positions if they are in the wrong order.
* Bubble sort is a stable, in-place sort algorithm.
*/

// Normal
function bubbleSortVariationNormal(arr) {
let swaps;
do {
swaps = false;
for (let i = 0; i < arr.length - 1; i++) {
const element = arr[i];
console.log(element);
if (arr[i] > arr[i + 1]) {
// start with the first two elements and sort them in ascending order. (Compare the element to check which one is greater).
let temp = arr[i + 1]; // store second element for swap
arr[i + 1] = arr[i]; // Swap first element to second element
arr[i] = temp; // // Swap second element to first element
swaps = true; // true for loop continue until Compare not false condition
}
}
} while (swaps);

return arr;
}

bubbleSortVariationNormal([6, 5, 3, 1, 8, 7, 2, 4]);
6 changes: 6 additions & 0 deletions src/hackerrank/problem-solving/algorithms-011-020.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ function gradingStudents(grades) {
}
return count;
}

/**
* 013: HackerLand University has the following grading policy:
*
*
*/