Public
Edited
Mar 21, 2023
Insert cell
Insert cell
[]+[]
Insert cell
![]
Insert cell
![]+[]
Insert cell
!![]+[]
Insert cell
![]+![]
Insert cell
!![]+![]
Insert cell
"hello"[0]
Insert cell
([]+![])[![]+![]]
Insert cell
(![]+[])[![]+![]]+(![]+[])[!![]+![]]+([]+!![])[!![]+![]]+([]+!![])[![]+![]]
Insert cell
(!![]+!![])**(!![]+!![]+!![])
Insert cell
[]+{}
Insert cell
[][[]]+[]
Insert cell
numToExpr(8)
Insert cell
function numToExpr(num) {
if(num==0) return '![]+![]';
if(num==1) return '!![]+![]';
const one = '!![]';
let exprArray = Array(num).fill(one);
let expr = exprArray.join('+');
return expr;
}
Insert cell
[[]][(![]+[])[!![]+![]]+([]+!![])[![]+![]]]+[]
Insert cell
stringsMap = new Map([
['false', '![]+[]'],
['true', '!![]+[]'],
['undefined', '[][[]]+[]'],
['[object Object]', '[]+{}'],
['function at() { [native code] }', '[[]][(![]+[])[!![]+![]]+([]+!![])[![]+![]]]+[]'], // engine dependent: different between Chrome (v8) and (Firefox & Safari)
]);
Insert cell
Insert cell
stringToExpr("fortitude")
Insert cell
function stringToExpr(inStr) {
const str = inStr.toString();
let chars = str.split('');
let outputExpr = [];
for (const char of chars) {
outputExpr.push(charToExpr(char));
}
return outputExpr.join('+');
}
Insert cell
viewof suite = createSuite({
name: "fartStrings",
timeout_ms: 100
})
Insert cell
suite.test("A passing test", () => {expect(true).toBe(true)})
Insert cell
suite.test("numToExpr: 5", () => {
expect(numToExpr(5)).toEqual("!![]+!![]+!![]+!![]+!![]")
})
Insert cell
suite.test("numToExpr: 1", () => {
expect(numToExpr(1)).toEqual("!![]+![]")
})
Insert cell
suite.test("numToExpr: 0", () => {
expect(numToExpr(0)).toEqual("![]+![]")
})
Insert cell
suite.test("charToExpr: f", () => {
let f = charToExpr("f");
expect(f).toEqual("(![]+[])[![]+![]]");
})
Insert cell
suite.test("charToExpr: r", () => {
expect(charToExpr('r')).toEqual("(!![]+[])[!![]+![]]")
})
Insert cell
suite.test("charToExpr: d", () => {
expect(charToExpr('d')).toEqual("([][[]]+[])[!![]+!![]]")
})
Insert cell
suite.test("charToExpr: i", () => {
expect(charToExpr('i')).toEqual("([][[]]+[])[!![]+!![]+!![]+!![]+!![]]")
})
Insert cell
suite.test("charToExpr: ' '", () => {
expect(charToExpr(' ')).toEqual("([]+{})[!![]+!![]+!![]+!![]+!![]+!![]+!![]]")
})
Insert cell
suite.test("charToExpr: 'v'", () => {
// Currently v8-compatible, but not JSC + SpiderMonkey
expect(charToExpr('v')).toEqual("([[]][(![]+[])[!![]+![]]+([]+!![])[![]+![]]]+[])[!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]]")
})
Insert cell
suite.test("eval: 'v'", () => {
// This will fail on EITHER v8 OR JavascriptCore & SpiderMonkey, depending on stringsMap
expect(eval(charToExpr('v'))).toEqual("v")
})
Insert cell
suite.test("charToExpr: 3", () => {
expect(charToExpr('3')).toEqual("(!![]+!![]+!![]+[])")
})
Insert cell
suite.test("stringToExpr: f", () => {
const fe = stringToExpr('f');
expect(eval(fe)).toEqual('f');
expect(stringToExpr('f')).toEqual("(![]+[])[![]+![]]")
})
Insert cell
suite.test("stringToExpr: fart", () => {
const fe = stringToExpr('fart');
expect(eval(fe)).toEqual('fart');
expect(stringToExpr('fart')).toEqual("(![]+[])[![]+![]]+(![]+[])[!![]+![]]+(!![]+[])[!![]+![]]+(!![]+[])[![]+![]]")
})
Insert cell
suite.test("stringToExpr: abcdefijlnorstuv ", () => {
const str = 'abcdefijlnorstuv ';
expect(eval(stringToExpr(str))).toEqual(str);
expect(stringToExpr(str)).toEqual("(![]+[])[!![]+![]]+([]+{})[!![]+!![]]+([]+{})[!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[!![]+!![]]+(![]+[])[!![]+!![]+!![]+!![]]+(![]+[])[![]+![]]+([][[]]+[])[!![]+!![]+!![]+!![]+!![]]+([]+{})[!![]+!![]+!![]]+(![]+[])[!![]+!![]]+([][[]]+[])[!![]+![]]+([]+{})[!![]+![]]+(!![]+[])[!![]+![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[![]+![]]+(!![]+[])[!![]+!![]]+([[]][(![]+[])[!![]+![]]+([]+!![])[![]+![]]]+[])[!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]]+([]+{})[!![]+!![]+!![]+!![]+!![]+!![]+!![]]")
})
Insert cell
suite.test("stringToExpr: 1234567890", () => {
expect(stringToExpr('1234567890')).toEqual("(!![]+![]+[])+(!![]+!![]+[])+(!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(![]+![]+[])")
})
Insert cell
(!![]+![]+[])+(!![]+!![]+[])+(!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(![]+![]+[])
Insert cell
![][0] // wat
Insert cell
([[]][(![]+[])[!![]+![]]+([]+!![])[![]+![]]]+[])
Insert cell
stringToExpr("at")
Insert cell
[[]]["at"]["bind"]
Insert cell
[[]]["entries"]()+[]
Insert cell
[[]]["at"]["bind"]([[]]["entries"]())
Insert cell
"".link() // it's deprecated, but it gives us: h / < > " =
Insert cell
("").constructor.name // ES2015, shame we still don't have the letter m
Insert cell
Object.getOwnPropertyNames("") // need w, m, P, N
Insert cell
Object.getPrototypeOf("")
Insert cell
import {createSuite, expect} from '@tomlarkworthy/testing';
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more