Published
Edited
Oct 7, 2022
Insert cell
Insert cell
Insert cell
Insert cell
x = ["a", "a", "b", "b", "b", "c", "c", "C", "c"]
Insert cell
x.includes("a")
Insert cell
x.length
Insert cell
string = []
Insert cell
function separatedata(Z){
for(let i=0; i<Z.length ; i++){
if (string.includes(Z[i])=== false){
string.push (Z[i])
}
}
return string
}
Insert cell
separatedata(x)
Insert cell
Insert cell
letterNumber = ({
a: 1,
b: 2,
c: 3,
C: 4
})
Insert cell
merge=[]
Insert cell
function mergeddata(X,Y){
var newArray = [];
for (let i = 0;i < X.length; ++i){
newArray.push (({name: X[i], number: letterNumber[X[i]]}))

// advance js, second parenthesis are holding two objects
}
return newArray
}
Insert cell
mergeddata(x)
Insert cell
x.length
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 matchaddresses(addresses, latLongs){
//create a variable
var combinedArray =[]
//create two loop to check both the arrays simultaneously. Remember to assign loops.
for (let a=0; a<addresses.length; a++){
for (let l=0; l<latLongs.length; l++){
//use if condition, to match address and latLong array then push the address and select the latLong to be pushed. I wasn't adding ['latLong'] in push that why was getting the entire array again. To go on the sub object, select the sub array name in the array.
if(addresses [a] === latLongs[l]['address']){
combinedArray.push ({'address': addresses [a], 'coordinates': latLongs[l]['latLong']})
}
}
}
return combinedArray
}
Insert cell
matchaddresses(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