Public
Edited
Jan 31, 2023
Insert cell
# FlattenList Recursive
Insert cell
solution = {
const input = test;
let result = new Array;
flattenlist(input, result);
return result;
}
Insert cell
function flattenlist(arr, arrout) {
arr.forEach(function(el) {
if (Array.isArray(el)) {
flattenlist(el, arrout);
}
else {
arrout.push(el);
}
});
}
Insert cell
function recursiveFactorial(n) {
if (n === 0) return 1;
return n * recursiveFactorial(n - 1);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
test = [1, "a", "b", [ "c", ["d",2 ] ], "e", [ [ [ "f" ] ] ] ];
Insert cell
data = FileAttachment("input.txt").text()
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