Published
Edited
Mar 13, 2019
Insert cell
Insert cell
Insert cell
Insert cell
function sumDigPow(a, b) {
// b - a + 1 give us the length of the array and then create one from Zero
return [...Array(b - a + 1).keys()]
// then we modify our array to start from 'a' to 'b'
.map( num => num + a )
// Check if number is equal to the result from reduce
.filter( num => num === [...num.toString(10)].reduce( (sum, cur, i) => sum + parseInt(cur) ** (i + 1), 0));
}
Insert cell
sumDigPow(1, 10)
Insert cell
sumDigPow(89, 150)
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