Instantly share code, notes, and snippets.

View fizzbuzz.js
function fizzbuzz() {
for (let i = 1; i <= 100; i++) {
let div3 = i % 3 == 0;
let div5 = i % 5 == 0;
if (div3 && div5) {
console.log("FizzBuzz");
}
else if (div3) {
console.log("Fizz");
}
View 1.js
let names = people.map(personToGetNameFrom => personToGetNameFrom.name);
// ******************
let getName = person => person.name;
let names = people.map(getName);
// ******************
function getName(person) { return person.name; }
View 1.js
// function copySession(sess) {
// return { ...sess };
// }
var copySession = compose(
reduce(
compose(
flip,
binary,
uncurry,
View 1.js
function Foo() {
var [x,setX] = useState(0);
var [y,setY] = useState(1);
var cb = useCallback(
function printXYIfChanged() { console.log(x,y); },
[x,y]
);
useEffect(
function pollingXY(){
var intv = setInterval(cb,100);
View 1.js
var a = "j"; // "j"
var b = "\\j"; // "\j"
var c = "\\\\j"; // "\\j"
var d = "\\\\\\j"; // "\\\j"
var e = "\\\\\\\\j"; // "\\\\j"
var f = "\\\\\\\\\\j"; // "\\\\\j"
var just_j = nonescapedRE("j");
just_j.test(a); // true
just_j.test(b); // false
View 1.js
var data = [
{ a: 4, b: 12, c: "elderberry" },
{ a: 2, b: 10, c: "cherry", d: 4 },
{ a: 4, b: 12, c: "durian" },
{ a: 2, b: 10, c: "cherry", },
{ a: 3, b: 12, c: "durian" },
{ a: 1, b: 10, c: "apple", },
{ a: 1, b: 11, c: "apple", },
{ a: 1, b: 11, c: "banana", },
{ a: 2, b: 10, c: "banana", },
View 1.js
"use strict";
[foo,bar] = TNG(foo,bar);
// NOTE: intentionally not TNG(..) wrapping useBaz(), so that it's
// basically like a "custom hook" that can be called only from other
// TNG-wrapped functions
function foo(origX,origY) {
var [x,setX] = useState(origX);
var [y,setY] = useState(origY);
View 1.js
class Foo {
constructor(x) { this.foo = x; }
hello() { console.log(this.foo); }
}
class Bar extends Foo {
constructor(x) { super(x); this.bar = x * 100; }
world() { console.log(this.bar); }
}
View 1.js
// https://medium.com/@alexgolec/google-interview-questions-deconstructed-the-knights-dialer-f780d516f029
function nearby(number) {
return (
number === 0 ? [4,6] :
number == 1 ? [6,8] :
number == 2 ? [7,9] :
number == 3 ? [4,8] :
number == 4 ? [3,9,0] :
number == 6 ? [1,7,0] :
View 1.js
function logger(strings,...values) {
var str = "";
for (let i = 0; i < strings.length; i++) {
if (i > 0) {
if (values[i-1] && typeof values[i-1] == "object") {
if (values[i-1] instanceof Error) {
if (values[i-1].stack) {
str += values[i-1].stack;
continue;
}