// Given a function `f` that maps from integers to integers, and a number
// `n` of characters to generate, produces a character sequence.
functioncharseq(f,n){
returnrange(n).map(f).map(toChar).join("")
}
// For example, using the identity function x => x, we get the
// alphabet.
alphabet={
functionidentity(x){
returnx;
}
returncharseq(identity,26)
}
// Given an integer `x`, return an array consisting of the range [0, 1, ... x-1]
functionrange(x){
vararr=[];
for(vari=0;i<x;i++){
arr.push(i);
}
returnarr;
}
range(10)
// Convert an integer to a letter in the range [a-z].
functiontoChar(x){
returnString.fromCharCode(x%26+97)
}
toChar(0)
toChar(25)
toChar(26)
// Reformat a long string into groups of 4 characters at a time, set on lines of 16 groups
functionlinebreaks(s){
// Inefficient, but who cares
varx=""
for(vari=0;i<s.length;i++){
if(i%64===0)x+="\n"
elseif(i%4===0)x+=" "
x+=s[i]
}
returnx.slice(1)
}
linebreaks(charseq((x)=>x,1024))
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.