Published
Edited
Sep 7, 2018
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Array.of(1,2,3)
Insert cell
Array.of(9)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let arr = [1 ,2 ,3, 4]
let add1 =[]
for(let i=0;i<arr.length;i++){
const temp = arr[i] + 1;
add1[i] = temp;
}
return add1
}
Insert cell
{
let arr = [1 ,2 ,3, 4]
let add1 = arr.map(x => x + 1)
return add1
}
Insert cell
Insert cell
Insert cell
Insert cell
{
Array.prototype.flatMap = function(fn) {
return Array.prototype.concat.apply([], this.map(fn));
}
let arr1 = [1, 2, 3, 4];

return [arr1.flatMap(x => [x * 2]) , arr1.map(x => [x * 2])];
}
Insert cell
Insert cell
Insert cell
Insert cell
{
let arr = [6,10,20,3]
let mapping = arr.map(factors)
let flatMapping = arr.flatMap(factors)
return { mapping , flatMapping }
}
Insert cell
Insert cell
Insert cell
{
let arr = [1,2,3,4,5,6]
let sum = 0
let product = 1
for(let i=0; i< arr.length;i++)
sum =sum + arr[i]
for(let i=0; i< arr.length;i++)
product = product * arr[i]

return { sum , product }
}
Insert cell

{
let arr = [1,2,3,4,5,6]
let sumFn = (a,b) => a + b
let productFn = (a,b) => a * b

return {
sum : arr.reduce(sumFn,0),
product : arr.reduce(productFn,1),
}
}
Insert cell
{
let arr = [1,2,3,4,5,6]
let max = 1
let min = 1
for(let i=0; i< arr.length;i++)
max = Math.max(max,arr[i])
for(let i=0; i< arr.length;i++)
min = Math.min(min,arr[i])
return { max , min }
}
Insert cell

{
let arr = [1,2,3,4,5,6]
let maxFn = (a,b) => Math.max(a,b)
let minFn =(a,b) => Math.min(a,b)
return {
max : arr.reduce(maxFn,-Infinity),
min : arr.reduce(minFn,Infinity),
}
}

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