Published
Edited
Oct 14, 2020
Insert cell
Insert cell
function reverse(arr) {
// Other way is to use reduce right
// return arr.reduceRight((a, e) => [...a, e], []);

return Array.from(arr, (e, i) => arr[arr.length - 1 - i]);

}
Insert cell
reverse([4, 5, 6])
Insert cell
function reverseStr(str) {
// return str
// .match(/\w+|\s/g)
// .reverse()
// .join('');
return str
.match(/\w+|\s?/g)
.reduceRight((a, b) => [...a, b], [])
.join('');
}
Insert cell
reverseStr('Hello world this')
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