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
class Grid { | |
// determine number of rows and columns. | |
constructor(rows, columns) { | |
this.rows = rows; | |
this.columns = columns; | |
} | |
// get the neighbors helper | |
getNeighbors(row, column) { |
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
class Grid { | |
constructor(rows, columns) { | |
this.rows = rows; | |
this.columns = columns; | |
} | |
getNeighbors(row, column) { | |
let neighbors = []; | |
if (!this.isValidCoord(row, column)) { |
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
// Example Input 1: | |
let phoneBook = [{name: 'Ann', number: "123-456-7890"}, {name: 'John', number: "234-567-8901"}, {name: 'John', number: "345-678-9012"} ]; | |
// Phone book is alphabetized | |
// ON Soln | |
// container for match {} | |
// loop through the array | |
// find match, save match to container | |
// return match.number |
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
// Storage O(1). | |
function removeDupes(arr) { | |
// sort the array | |
arr = arr.sort((a, b) => { | |
return a - b; | |
}); | |
// pointer 1 | |
p1 = 0; |
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
// O(N) | |
function remDupes(arr) { | |
// have we seen this? | |
let hash = []; | |
// pointer 1 | |
p = -1; | |
// establish i as pointer 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
// only list duplicates once | |
// return array of duplicates | |
// helper findInstances(array) | |
// obj | |
// loop through array | |
// if no key in obj, create key | |
// return obj | |
// main findSimilar(arr1, arr2) |
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
// Input: int, divInt | |
// Output: int | |
// helper | |
// return whole sets & remainder | |
// input: int, divInt | |
// output: [sets, remainder] | |
// main | |
// fin str |
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
// Input: str | |
// Output: true or false | |
// Example: madam -> 5 length, odd | |
// Example: wowwow -> 6 length, even | |
// Example: hello -> fail, odd | |
// Example: hi -> fail, even | |
// isPalindrome(str) | |
// midpoint str/2 ceil -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
// Inputs: int, divideByInt | |
// Output: Int | |
// Sets | |
// Current Set | |
// Loop through int | |
// if current < divide | |
// current ++ |
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
// Roman Numerals | |
// I, II, III, IV, V, VI, VII, VIII, IX, X | |
// X, XX, XX, XL, L, LX, LXX, LXXX, XC, C | |
// C, CC, CCC, CD, D, DC, DCC, DCCC, CM, M | |
// EXAMPLES: | |
// 2018: MM X VIII | |
// 199: C XC IX | |
// Input: Integer |
NewerOlder