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
// Simple caching in Javascript using the new Logical nullish assignment (??=) operator | |
class FibClass { | |
// Private field to store a value | |
#fib = null | |
// Fibonacci sequence method (recursive calculation) | |
f (n) { | |
return n < 3 ? 1 : this.f(n - 1) + this.f(n - 2) | |
} |
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
/* https://www.reddit.com/r/dailyprogrammer/comments/7eh6k8/20171121_challenge_341_easy_repeating_numbers/ */ | |
const input = '124489903108444899' | |
const numbers = {} | |
for(let digits = 2; digits < input.length; digits++) { | |
for(let index = 0; index < input.length - digits + 1; index++) { | |
let chunk = input.substr(index, digits) | |
chunk in numbers ? | |
numbers[chunk]++ : |
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
// tic tac toe | |
// paste into console, type play(x,y) to take turn | |
// ex: play(2,2) plays bottom right corner tile | |
const boardInit = () => [[null, null, null],[null, null, null],[null,null,null]] | |
const players = ['o', 'x'] | |
let board = boardInit() | |
let currentPlayerIndex = 0; | |
const currentPlayer = () => players[currentPlayerIndex] | |
const nextPlayer = () => currentPlayerIndex = +!currentPlayerIndex |
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
const objValuesAsString = obj => { | |
return obj instanceof Object ? Object.values(obj).map(objValuesAsString).join(' ') : obj; | |
}; |
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
[{ | |
"table": [{ | |
"class": ["class-for-table"] | |
}, { | |
"a": [{ | |
"rel": "something", | |
"href": "a-url-here" | |
}, [ | |
"this is a text node" | |
]] |