Public
Edited
Oct 31, 2023
Insert cell
Insert cell
Insert cell
"samuel".split("").reduce((acc, cv) => acc + ascii[cv], 0)
Insert cell
abc = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z"
]
Insert cell
function findNthPrime(n) {
let count = 0;
let num = 1;

function isPrime(number) {
if (number < 2) return false;
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) return false;
}
return true;
}

while (count < n) {
num++;
if (isPrime(num)) {
count++;
}
}

return num;
}
Insert cell
findNthPrime(0)
Insert cell
function getHash(key) {
return (
key
.split("")
.map((k) => findNthPrime(abc.findIndex((ab) => ab === k) + 1))
.reduce((acc, cv) => acc + cv, 0) % 10
);
}
Insert cell
[getHash("esther"), getHash("ben"), getHash("bob"), getHash("dan")]
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