Public
Edited
May 21, 2023
Insert cell
Insert cell
x = [1, 2, 3]
Insert cell
x.map((i) => i + 1)

Insert cell
myArray = [3, 4, 5]
Insert cell
myA2 = []
Insert cell
j = {
let mya = [1, 2, 3];
let mya2 = [];
mya.forEach((i) => {
mya2.push(i ** 2);
});
return mya2;
}
Insert cell
p = {
function addtwo(x, y) {
return x + y;
}
return addtwo(1, 2);
}
Insert cell
q = {
const x = 12;
function addthree(x, y, z) {
return x + y + z;
}
return addthree(x, 10, 10);
// x is declared global
}
Insert cell
z = {
function square(x) {
return x ** 2;
}
//return square(10);
// return when you want to use this function as an intermediary
function sum_sq(i, j) {
return square(i) + square(j);
}
return [square(10), sum_sq(10, 12)];
}
Insert cell
q
Insert cell
{
const x = [1, 2, 3];
const j = x.map((i) => i ** 2); //return an array of squared values
return j;
}
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