Published
Edited
Aug 31, 2020
Insert cell
Insert cell
function assert(isTrue, message) {
if(!isTrue) {
return message;
}
return null;
}
Insert cell
Insert cell
data = [
{ name: "Dan", age: 23, superhuman: false },
{ name: "Sleepwalker", age: NaN, superhuman: "TRUE" }
]
Insert cell
Insert cell
function checkDataContent(data) {
return data.reduce((arr, d) => {
const dString = JSON.stringify(d);
let msgs = [];
msgs.push(assert(_.isString(d.name), dString + " has a bad name - should be a string"));
msgs.push(assert(_.isNumber(d.age), dString + " has a bad age - should be a number"));
msgs.push(assert(!_.isNaN(d.age), dString + " has a bad age - should not be NaN"));
msgs.push(assert(_.isBoolean(d.superhuman), dString + " has a bad superhuman - should be boolean"));
return arr.concat(msgs.filter(d => d !== null))
}, [])
}
Insert cell
Insert cell
Insert cell
function checkDataShape(data) {
let msgs = [];
msgs.push(assert(data.length > 0, "data is empty"));
msgs.push(assert(data.length > 4, "data is too small"));
var keys = Object.keys(data[0]);
msgs.push(assert(keys.length === 4, "wrong number of columns"));
return msgs.filter(d => d !== null);
}
Insert cell
Insert cell
Insert cell
_.isEqual({ tea: 'green' }, { tea: 'green' })
Insert cell
_.isEqual({ tea: 'earl' }, { tea: 'green' })
Insert cell
Insert cell
Insert cell
_ = require("lodash")
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