Published
Edited
Feb 14, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
file = {
const resp = await fetch(dicturl)
const text = await resp.text()
return text.split("\n")
}
Insert cell
Insert cell
words = {
const isnoncomment = line => line[0] !== "#"
const issmallword = word => word.length > 3 && word.length < 7
const validwords = word => isnoncomment(word) && issmallword(word)
const datalines = file.filter(validwords)
return datalines
}
Insert cell
Insert cell
wordpair = () => {
// util functions
const random = max => Math.trunc( Math.random() * (max + 1) ) // gets a random number between 0 to max, inclusive
const maxindex = array => array.length - 1 // gets the array's maximum valid index
// first word
const first = words[random(maxindex(words))]
// second word
const possiblesecond = (
word => (
first.length + word.length === 10
&&
word !== first
)
)
const possibleseconds = words.filter(possiblesecond)
const second = possibleseconds[random(maxindex(possibleseconds))] || ""
// format first and second words into camel case password: "firstSecond"
const titlecase = word => word[0].toUpperCase() + word.slice(1)
const secondCapped = second[0].toUpperCase() + second.slice(1)
const pair = first + secondCapped
return { pair, first, second }
}
Insert cell
Insert cell
wordpairs = count => {
const pairs = []
for(let i = 0; i < count; i++) {
pairs.push(wordpair())
}
return pairs
}
Insert cell
pairs = wordpairs(count)
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