Published
Edited
Oct 10, 2022
1 star
Insert cell
Insert cell
Insert cell
x = ["a", "a", "b", "b", "b", "c", "c", "C", "c"]
Insert cell
unique1 = x.filter((item, i, ar) => ar.indexOf(item) === i);
Insert cell
function unique (arr) {
var newArr = []
newArr = arr.filter((item, i, arr) => arr.indexOf(item) === i);
return newArr
}
Insert cell
unique(x)
Insert cell
Insert cell
letterNumber = ({
a: 1,
b: 2,
c: 3,
C: 4
})
Insert cell
function mergeFunction (orig, merg) {
var newArray = []
for (let i = 0; i < orig.length; i++) {
newArray.push(
({name: orig[i], number: merg[orig[i]]})
)
}
return newArray
}
Insert cell
mergeFunction(x, letterNumber)
Insert cell
Insert cell
addresses = ["2 W 13th St, New York, NY 10011", "55 W 13th St, New York, NY 10011", "1000 5th Ave, New York, NY 10028", "2 W 13th St, New York, NY 10011", "2 W 13th St, New York, NY 10011"]
Insert cell
addresses.length
Insert cell
latLongs = [({address: "2 W 13th St, New York, NY 10011", latLong: [40.735439, -73.994728]}), ({address: "1000 5th Ave, New York, NY 10028", latLong: [40.779079, -73.962578]}), ({address: "55 W 13th St, New York, NY 10011", latLong: [40.736561, -73.996460]})]
Insert cell
latLongs.length
Insert cell
function mergeFunction2(addresses, latLongs){
let newArray = []
for (let i = 0; i < addresses.length; i++){
for (let k=0; k < latLongs.length; k++){
if (addresses[i] === latLongs[k]['address']){
newArray.push({'address': addresses[i], 'latLong': latLongs[k]['latLong']})
}
}
}
return newArray
}
Insert cell
mergeFunction2(addresses,latLongs)
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