Published
Edited
Mar 11, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable output2 = RiTa.grammar(ruleB).expand()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function expandRule(rule) {
return RiTa.grammar(rule).expand();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function fetchWordsInArr(arr, command) {
let newArr = [];

for (var i = 0; i < arr.length; i++) {
let w = arr[i].word;
let url = `https://api.datamuse.com/words?${command}=${w}`;
let response = await fetch(url);
// .then(response => {
// let resJson = response.json();
// let newWord = resJson[0].word;
// newArr[i] = { word: newWord, loc: arr[i].loc };
// })
// .catch(err => {
// return "error";
// newArr[i] = { word: w, loc: arr[i].loc };
// });

let resJson = await response.json();

let newWord;
if (isEmpty(resJson)) {
newWord = w;
} else {
newWord = resJson[0].word;
}
newArr[i] = { word: newWord, loc: arr[i].loc };
}

return newArr;
}
Insert cell
Insert cell
Insert cell
Insert cell
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