Public
Edited
Feb 14
Importers
Insert cell
Insert cell
alignWords = function(reduct_json, secondsAtEndOfText = 3) {
let a = [];
Object.keys(reduct_json).forEach(segments => {
reduct_json[segments].forEach(speech => {
a = a.concat(speech.wdlist);
});
});
a.forEach((word, index) => {
word.word = word.word.trim();
index < a.length - 1
? (word.gap = a[index + 1].start - word.end)
: (word.gap = secondsAtEndOfText);
});
return a;
}
Insert cell
heads = () => {
return randInt(2) == 0;
}
Insert cell
mod = function (n, m) {
// mod function that handles negative numbers, usage: mod(num, modulous)
return ((n % m) + m) % m;
}
Insert cell
randInt = maxPlusOne => (maxPlusOne * Math.random()) | 0
Insert cell
randInt(2)
Insert cell
randElement = (array) => array[randInt(array.length)]
Insert cell
randIntBetween = (min, max) => {
return Math.floor(Math.random() * (max - min) + min);
}
Insert cell
shuffle = (a) => {
let i = a.length;
if (i < 2) return a;
while (--i > 0) {
let j = ~~(Math.random() * (i + 1)); // ~~ is a common optimization for Math.floor
let t = a[j];
a[j] = a[i];
a[i] = t;
}
return a;
}
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