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
| //SET UP | |
| const users = [{ | |
| id: 1, | |
| name: 'Bob', | |
| schoolId: 101 | |
| }, { | |
| id: 2, | |
| name: 'Jane', | |
| schoolId: 999 |
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
| // Functional JS to flatten an array... | |
| const flatten = (array) => { | |
| return array.reduce((flat, toFlatten) => { | |
| return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
| }, []); | |
| } | |
| console.log(flatten([[1,2,[3]],4])); |
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
| 'use strict'; | |
| /** | |
| * Shape class. | |
| * | |
| * @constructor | |
| * @param {String} id - The id. | |
| * @param {Number} x - The x coordinate. | |
| * @param {Number} y - The y coordinate. | |
| */ |
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 reverseString(str) { | |
| return str.split('').reverse().join('') | |
| } | |
| console.log(reverseString('Hello')) | |
| // Recursion | |
| function reverseString(str) { | |
| return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0); |
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
| // Basic Recursion | |
| const countDownFrom = (num) => { | |
| if (num === 0) return | |
| console.log(num) | |
| countDownFrom(num - 1) | |
| } | |
| countDownFrom(10) |
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 LinkedList() { | |
| this.head = null; | |
| } | |
| LinkedList.prototype.isEmpty = function() { | |
| return this.head === null; | |
| }; | |
| LinkedList.prototype.size = function() { | |
| var current = this.head; |
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
| Mark Williams | waffle iron | 80 | 2 | |
|---|---|---|---|---|
| Mark Williams | blender | 200 | 1 | |
| Mark Williams | knife | 10 | 4 | |
| Nikita Smith | waffle iron | 80 | 1 | |
| Nikita Smith | knife | 10 | 2 | |
| Nikita Smith | pot | 20 | 3 |
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
| var _ = {}; | |
| /*********IDENTITY**********/ | |
| _.identity = function(val) { | |
| return val; | |
| }; | |
| /*********FIRST**********/ | |
| _.first = function(array, n) { |
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
| /** | |
| |-------------------------------------------------- | |
| | CLASSES | |
| |-------------------------------------------------- | |
| */ | |
| class Point { | |
| constructor(x, y) { | |
| this.x = x; | |
| this.y = y; |
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
| Object.equals = (x, y) => { | |
| if (x === y) return true; | |
| if (!(x instanceof Object) || !(y instanceof Object)) return false; | |
| if (x.constructor !== y.constructor) return false; | |
| for (let p in x) { | |
| if (!x.hasOwnProperty(p)) continue; | |
| if (!y.hasOwnProperty(p)) return false; | |
| if (x[p] === y[p]) continue; | |
| if (typeof x[p] !== 'object') return false; |
OlderNewer