This file contains hidden or 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 === 1) { | |
return arr; | |
} | |
const center = Math.floor(arr.length / 2); | |
const left = arr.slice(0, center); | |
const right = arr.slice(center); | |
return merge(mergeSort(left), mergeSort(right)); | |
} |
This file contains hidden or 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
//forEach | |
Array.prototype.myforEach = function(cb) { | |
for (let i = 0; i < this.length; i++){ | |
cb(this[i], i, this); | |
} | |
return undefined; | |
}; |