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 almostIncreasingSequence(sequence) { | |
var i = 0; | |
var spliced; | |
function checkValid(arr) { | |
if (i > sequence.length) { | |
return false | |
} |
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 merge(arr1, arr2) { | |
let i = 0; | |
let j = 0; | |
let merged = []; | |
let arr1Full = false; | |
let arr2Full = false; | |
while (arr1Full === false && arr2Full === false) { |
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 insertionSort(arr){ | |
var currentVal; | |
for(var i = 1; i < arr.length; i++){ | |
currentVal = arr[i]; | |
for(var j = i - 1; j >= 0 && arr[j] > currentVal; j--) { | |
arr[j+1] = arr[j] | |
} | |
arr[j+1] = currentVal; |
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 insertionSort(arr) { | |
for (var i = 1; i < arr.length; i++) { | |
if (arr[i] < arr[i-1]) { | |
for (var j = 0; j <= i; j++) { | |
if (arr[j] > arr[i]) { | |
var temp = arr[j]; | |
arr[j] = arr[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 selectionSort(arr) { | |
let currentMin = 0; | |
let newMin = 0; | |
let complete = false; | |
while (!complete) { | |
for (var i = currentMin; i < arr.length; 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 subStr(str, sub) { | |
let i = 0; | |
let j = 0; | |
let collected = ''; | |
let counter = 0; | |
let complete = false; | |
while (complete === false) { |
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 binarySearch(arr, elem) { | |
var start = 0; | |
var end = arr.length - 1; | |
var middle = Math.floor((start + end) / 2); | |
while(arr[middle] !== elem && start <= end) { | |
if(elem < arr[middle]){ | |
end = middle - 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 findSum(arr, sum) { | |
var i = 0; | |
var j = arr.length-1; | |
var complete = false; | |
while (complete === false) { | |
if(arr[i] + arr[j] === sum) { | |
complete = true; | |
return [arr[i], arr[j]]; |
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 generateFibonacci(length){ | |
let sequence = [1]; | |
for(var i = 1; i <= length; i++){ | |
if (sequence.length === 1) { | |
sequence[i] = 1 | |
} | |
else{ | |
sequence[i] = sequence[i-1] + sequence[i - 2] |
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){ | |
let sortOccurred = true; | |
while (sortOccurred === true) { | |
for(var i = 0; i < arr.length; i++){ | |
if (arr[i] > arr[i + 1]) { | |
var a = arr[i]; | |
arr[i] = arr[i + 1]; |
NewerOlder