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
const swap = (array, firstItemIndex, lastItemIndex) => { | |
const temp = array[firstItemIndex]; | |
array[firstItemIndex] = array[lastItemIndex]; | |
array[lastItemIndex] = temp; | |
} | |
const heapify = (heap, i, max) => { | |
let index, leftChild, righChild; |
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
const items = [5,3,7,6,2,9]; | |
function swapNumbers(items, leftIndex, rightIndex){ | |
const temp = items[leftIndex]; | |
items[leftIndex] = items[rightIndex]; | |
items[rightIndex] = temp; | |
} | |
function partition(items, left, right) { | |
const pivotNumber = items[Math.floor((right + left) / 2)] | |
while (left <= 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 swapNumbers(items, leftIndex, rightIndex){ | |
const temp = items[leftIndex]; | |
items[leftIndex] = items[rightIndex]; | |
items[rightIndex] = temp; | |
} | |
function insertionSort(array = []) { | |
for(let i = 0; i < array.length; i++) { | |
let currentIndex = i | |
while(currentIndex > 0 && array[currentIndex] < array[currentIndex - 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 mergeSort (array= []) { | |
if (array.length == 1) return array | |
const middle = Math.floor(array.length / 2) | |
const leftHalf = array.slice(0, middle) | |
const rightHalf = array.slice(middle) | |
return mergeHalves( | |
mergeSort(leftHalf), |
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 Node(value){ | |
this.value = value | |
this.left = null; | |
this.right = null; | |
} | |
Node.prototype.toString = function() { | |
return this.value; | |
} |
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 Node(value){ | |
this.value = value | |
this.left = null; | |
this.right = null; | |
} | |
Node.prototype.toString = function() { | |
return this.value; | |
} |
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
// Bad Case | |
class Staff { | |
constructor(staff) { | |
this.staff = staff; | |
} | |
registerStaff(staff) { | |
if (this.validateUser(staff)) { | |
return `${staff} has been created`; | |
} |
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
// Bad | |
class Bird{} | |
class FlyingBird extends Bird { | |
constructor(type, name){ | |
super(); | |
this.name = name | |
} | |
flightSpeed(){ | |
if(this.name === "parrot" || this.name === "dove"){ | |
return ('I can fly medium-fast') |
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
// bad | |
class Bird{ | |
fly(){ | |
console.log('I can fly') | |
} | |
} | |
class Duck extends Bird { | |
constructor(){ | |
super(); | |
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
// bad | |
class Post { | |
constructor(){ | |
} | |
editPost(){ | |
console.log('Post edited') | |
} | |
createPost(){ |
OlderNewer