Published
Edited
Sep 23, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
coats = csv.getRows().filter(row => {
return (
row.getString('Object Name') == 'Coat' &&
row.getString('Object Begin Date') == '1970'
);
})
Insert cell
dress = csv.getRows().filter(row => {
// Using "Includes" is better than
// using a hard coded string comparison, because
// if our title is "Cocktail Dress" for instane,
// then it will not be removed from our dataset
return row.getString('Object Name').includes('Dress');
// Compare this to the output below.
});
Insert cell
dressStrict = csv.getRows().filter(row => {
return row.getString('Object Name') == 'Dress';
});
Insert cell
Insert cell
Insert cell
Insert cell
uniqueNames = {
let unique = {};

csv.getRows().forEach( row => {
if( !unique[row.getString("Object Name")] ){
unique[row.getString("Object Name")] = 1;
} else {
unique[row.getString("Object Name")] += 1;
}
});
return unique;
}
Insert cell
Object.keys(uniqueNames).length
Insert cell
Insert cell
sortedUniqueNames = {
// this uses a "selection sorting" algorithm
// reference: https://en.wikipedia.org/wiki/Selection_sort
let usedValues = [];
let sorted = [];
while ( !(sorted.length >= Object.keys(uniqueNames).length) ){
let max = { "name": '', "value": '' };
for (let key in uniqueNames){
if (
uniqueNames[key] > max.value &&
!usedValues.includes(key)
){
max.name = key;
max.value = uniqueNames[key];
usedValues.push(key);
}
}
sorted.push(max);
}
return sorted;
}
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