Public
Edited
Dec 9
33 forks
5 stars
Insert cell
Insert cell
Insert cell
// instead of myArray.push(element)
function push(element, array) {
// TODO return a new array with the new element at the end
}
Insert cell
prePush = [1, 2, 3]
Insert cell
postPush = push(4, prePush)
Insert cell
Insert cell
Insert cell
// instead of myArray[index] = value
function update(index, value, array) {
// TODO return a new copy of the array with the given value at index
}
Insert cell
preUpdate = ["spellling", "is", "hard"]
Insert cell
postUpdate = update(0, "spelling", preUpdate)
Insert cell
Insert cell
Insert cell
// instead of myArray.pop();
function pop(array) {
// TODO return a new array with the last old element removed
}
Insert cell
prePop = [1, 2, 3, 'popMe']
Insert cell
postPop = pop(prePop)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Immutable = require('immutable')
Insert cell
immutableList = Immutable.List([1, 2, 3])
Insert cell
newList = immutableList.push(4)
Insert cell
immutableList.size
Insert cell
newList.size
Insert cell
immutableMap = Immutable.Map({ a: 1, b: 2, c: 3 })
Insert cell
newMap = immutableMap.set('c', 4)
Insert cell
newerMap = newMap.set('d', 5)
Insert cell
immutableMap.get('c')
Insert cell
newMap.get('c')
Insert cell
newMap.get('d')
Insert cell
newerMap.get('d')
Insert cell
Insert cell
immer = import("https://cdn.jsdelivr.net/npm/immer@latest/+esm")
Insert cell
immer.produce
Insert cell
regularJSArray = [1, 2, 3]
Insert cell
newArray = immer.produce(regularJSArray, draft => {
draft.push(4);
})
Insert cell
regularJSArray.length
Insert cell
newArray.length
Insert cell
newerArray = immer.produce(newArray, draft => {
draft[0] = 5;
})
Insert cell
newerArray[0]
Insert cell
newArray[0]
Insert cell
regularJSObject = ({ a: 1, b: 2, c: 3 }) // parentheses required when creating objects like this in Observable
Insert cell
newObject = immer.produce(regularJSObject, draft => {
draft.c = 4;
})
Insert cell
newObject.c
Insert cell
regularJSObject.c
Insert cell
newerObject = immer.produce(newObject, draft => {
draft.d = 5;
})
Insert cell
newerObject.d
Insert cell
newObject.d
Insert cell
Insert cell
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