This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkSum(arr, sum) { | |
let low = 0, | |
high = arr.length - 1; | |
while(low < high) { | |
let s = arr[low] + arr[high]; | |
if (s === sum) return true | |
if (s < sum) { | |
low = low + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fizzBuzz(to) { | |
for (var i=1; i <= to; i++) { | |
if (i % 15 == 0) | |
console.log("FizzBuzz"); | |
else if (i % 3 == 0) | |
console.log("Fizz"); | |
else if (i % 5 == 0) | |
console.log("Buzz"); | |
else | |
console.log(i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeSort (arr) { | |
if (arr.length < 2) { | |
return arr; | |
} | |
var mid = Math.floor(arr.length / 2); | |
var subLeft = mergeSort(arr.slice(0, mid)); | |
var subRight = mergeSort(arr.slice(mid)); | |
return merge(subLeft, subRight); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var quickSort = function(array, left, right){ | |
var leftIndex = partition(array, left, right); | |
if (left < leftIndex - 1){ | |
quickSort(array, left, leftIndex-1); | |
} | |
if (right > leftIndex){ | |
quickSort(array, leftIndex, right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bubbleSort(arr) { | |
for (var i = 0; i < arr.length - 1; i++) { | |
for(var j = 0; j < arr.length - i - 1; j++ ) { | |
if (arr[j] > arr[j + 1]) { | |
var temp = arr[j]; | |
arr[j] = arr[j + 1]; | |
arr[j + 1] = temp; | |
} | |
} | |
} |
NewerOlder