function reducerFn(output, value) {
// reducer functions know how to build a structure when repeatedly given
// that structure and values (think of it as 'builder')
return output
}
function reduceFn(collection, reducerFn, output) {
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 Op { | |
constructor(symbol, precedence, leftAssociate, apply) { | |
Object.assign(this, {symbol, precedence, leftAssociate, apply}) | |
} | |
process(stack) { | |
if (this.apply === null) return | |
const args = [] | |
for (let i = 0; i < this.apply.length; i++) { | |
const arg = stack.pop() | |
if (arg === undefined) { |
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
const min = (a,b) => (a < b) ? a : b // this works on big ints too, unlike Math.min | |
const err = message => {throw new Error(message)} // useful if you want to throw an error in an expression | |
const castToNumber = bigInt => (BigInt(bigInt) <= Number.MAX_SAFE_INTEGER) ? Number(bigInt) : err(`Number too big: ${bigInt} > MAX_SAFE_INTEGER`) | |
const prefixTo = (array, length) => (array.length >= length) ? array : [...Array(length - array.length).fill(0), ...array] | |
const factorial = (() => { | |
const lookupTableSize = 20 | |
let lastVal = 1n | |
const lookUp = Array.from({length: lookupTableSize}, (_,i) => lastVal = i === 0 ? lastVal : BigInt(i) * lastVal) | |
return function factorial(n) { |
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
<html> | |
<head> | |
<style> | |
body { | |
background-color: turquoise; | |
} | |
#age { | |
color: white; | |
font-size: xxx-large; |
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
<html> | |
<head> | |
<style> | |
body { | |
background-color: turquoise; | |
} | |
#age { | |
color: white; | |
font-size: xxx-large; |
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
<html> | |
<head> | |
<title>React</title> | |
<script type="application/javascript" crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script type="application/javascript" crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
</head> | |
<body> | |
<div id="root"></div> | |
<script type="application/javascript"> |
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
const fetch = require('node-fetch'); | |
const lotteries = { | |
lotto: { | |
balls: [ | |
{number: 6, from:1, to: 59} | |
] | |
}, | |
euromillions: { | |
balls: [ |
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
const line = '"" "a b" "a b c" "a \\" marvellous" \'we like\'a"b a""b abab abb "hi"'; | |
const gre = /\s*(?:(?:"((?:\\"|[^"])*)")|(?:'((?:\\'|[^'])*)')|([^\s]+))/g; | |
function split(str) { | |
const result = []; | |
str.replace(gre, (part, dquoteMatch, squoteMatch, wsMatch, offset, fullString) => { | |
result.push(dquoteMatch !== undefined ? dquoteMatch : squoteMatch !== undefined ? squoteMatch : wsMatch) | |
}); | |
return result; | |
} |
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 should probably use Vorpal.js instead of this. | |
// usage demo down at the bottom of the file... | |
const Repl = require('repl'); | |
const util = require('util'); | |
const fs = require('fs'); | |
const path = require('path'); | |
// Don't be a repli-can't, be a... | |
class Replican { |
I hereby claim:
- I am kybernetikos on github.
- I am kybernetikos (https://keybase.io/kybernetikos) on keybase.
- I have a public key whose fingerprint is 4D54 659A DBC4 D807 220C 03E4 7DD3 2D18 A8D8 2630
To claim this, I am signing this object:
NewerOlder