Skip to content

Instantly share code, notes, and snippets.

View northamerican's full-sized avatar
🚲

Chris Bitsakis northamerican

🚲
View GitHub Profile
@northamerican
northamerican / simple-caching-logical-nullish-assignment.js
Created February 11, 2021 23:50
Simple caching in Javascript using the new Logical nullish assignment (??=) operator
// 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)
}
@northamerican
northamerican / challenge-341-repeating-numbers.js
Created December 22, 2017 08:56
challenge 341: repeating numbers
/* 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]++ :
@northamerican
northamerican / console-log-tic-tac-toe.js
Last active December 8, 2017 03:42
console tic tac toe
// 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
@northamerican
northamerican / objValuesAsString.js
Last active July 24, 2017 23:55
get all values inside an object or array recursively as a string for search matching or filtering
const objValuesAsString = obj => {
return obj instanceof Object ? Object.values(obj).map(objValuesAsString).join(' ') : obj;
};
@northamerican
northamerican / minimalist-html-in-json-alt.json
Last active July 24, 2017 23:56
minimalist html in json
[{
"table": [{
"class": ["class-for-table"]
}, {
"a": [{
"rel": "something",
"href": "a-url-here"
}, [
"this is a text node"
]]