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
import ClassicComponent from '@ember/component'; | |
export default class extends ClassicComponent { | |
tagName = ''; | |
} |
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
let truths = [ | |
[ 'a', 1 ], | |
[ 'b', 2 ], | |
[ 'c', 1, 2 ], | |
[ 'd', 3 ], | |
[ 'e', 3, 4 ] | |
]; | |
function permutations(input, index = 0, prefix = [], stack = []) { |
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
/** | |
* You have an array of "truths" represented in the form: | |
* | |
* [ subjectA, condition1, condition2 ] | |
* | |
* which means subjectA satisfies condition1 and condition2. | |
* | |
* Create an algorithm which generates all possible truth permutations in the form: | |
* | |
* [ [...conditions], [...subjects] ] |
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: 1, 2, 3, 4 | |
* Output: | |
* 1 | |
* 1, 2 | |
* 1, 2, 3 | |
* 1, 2, 3, 4 | |
* 1, 2, 4 | |
* 1, 3 | |
* 1, 3, 4 |
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
// MY updated solution (merge sort implementation): | |
/** | |
* Definition for singly-linked list. | |
* function ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** |
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
// https://leetcode.com/problems/clone-graph/ | |
/** | |
* // Definition for a Node. | |
* function Node(val, neighbors) { | |
* this.val = val === undefined ? 0 : val; | |
* this.neighbors = neighbors === undefined ? [] : neighbors; | |
* }; | |
*/ |
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
// Solution to https://www.interviewcake.com/question/javascript/find-duplicate-optimize-for-space-beast-mode | |
function findDuplicate(intArray) { | |
// Find a number that appears more than once ... in O(n) time | |
let n = 0; | |
let pos = intArray[intArray.length - 1]; | |
// Get into the cycle | |
while (n < intArray.length) { |
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 quickSort(data, left = 0, right = data.length - 1) { | |
if (right <= left) { | |
return data; | |
} | |
let split = partition(data, left, right); | |
quickSort(data, left, split - 1); | |
quickSort(data, split + 1, 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 hash(str) { | |
let hash = 5381; | |
for (let i = 0; i < str.length; i++) { | |
hash = hash * 33 + str.charCodeAt(i); | |
hash |= 0; | |
} | |
return hash; | |
} | |
function HashTable() { |
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, start = 0, length = arr.length) { | |
if (length <= 1) { | |
return length == 1 ? [ arr[start] ] : []; | |
} | |
let halfLength = Math.floor(length / 2); | |
let left = mergeSort(arr, start, halfLength); | |
let right = mergeSort(arr, start + halfLength, length - halfLength); | |
let leftIdx = 0; |
NewerOlder