Public
Edited
Oct 16, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
is_null = null
Insert cell
Insert cell
Insert cell
y == 6.7
Insert cell
Insert cell
Insert cell
example_array = [5, 6, 7, 8, 9, 10]
Insert cell
Insert cell
example_array_with_mixed_types = ["Banana", 8, true]
Insert cell
Insert cell
Insert cell
example_array[1]
Insert cell
Insert cell
Insert cell
example_array.length == 6
Insert cell
// what's wrong with what i just wrote?
example_array[example_array.length-1]
Insert cell
Insert cell
Insert cell
example_array_with_mixed_types.push("pushed")
Insert cell
example_array_with_mixed_types
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
car.type
Insert cell
car["type"]
Insert cell
Insert cell
example_map = new Map()
Insert cell
example_map.set("a", "b")
Insert cell
example_map
Insert cell
example_map.get("a")
Insert cell
Insert cell
Insert cell
gimme_5 = () => 5
Insert cell
gimme_5()
Insert cell
Insert cell
add_5 = the_thing_im_going_to_change=>the_thing_im_going_to_change+5
Insert cell
add_5(4)
Insert cell
function add_1(x){
return x+1;
}
Insert cell
function which_is_larger(x, y){
if (x>y) {
return x;
}
else {
return y;
}
}
Insert cell
which_is_larger(5,6)
Insert cell
Insert cell
Insert cell
1+1
Insert cell
Insert cell
{return 1+1;}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
var local_var_example = "this is local";
const this_is_a_local_but_constant = "you can't change me";
//this_is_a_local_but_constant = this_is_a_local_but_constant + "i'm trying to change you"
local_var_example = local_var_example + " and i changed it";
return local_var_example;
}
Insert cell
local_var_example
Insert cell
Insert cell
a_global_variable = "this is global"
Insert cell
a_global_variable
Insert cell
{
return a_global_variable + " and im doing something to it"
}
Insert cell
// If you uncomment the next line, things will break!
//a_global_variable = "trying to change it"
Insert cell
Insert cell
Insert cell
{
if (a_global_variable=="this is global"){
return "whew! good thing we checked!";
}
else{
return "oh no it's not what we thought!";
}
}
Insert cell
Insert cell
a_global_variable=="this is global" ? "whew! good thing we checked!" : "oh no it's not what we thought!"
Insert cell
Insert cell
Insert cell
{
var y = 1;
for(var x=5; x<8; x=x+1){
y=y+x;
}
return y;
}
Insert cell
{
var arrests=["housed", "unhoused", "housed", "unhoused", "housed", "housed", "unhoused"]
var count_housed = 0;
var count_unhoused = 0;
for(var x=0;x<arrests.length;x=x+1){
console.log("x");
console.log(x);
if (arrests[x]=="housed"){
count_housed+=1;
console.log("count housed");
console.log(count_housed);
}
else{
count_unhoused+=1;
}
}
return count_unhoused*100/arrests.length
}
Insert cell
test_array = ["what","index","is","blue","in","this","sentence"]
Insert cell
{for(var x=0;x<test_array.length;x+=1){
if (test_array[x]=="blue"){
console.log("im executing");
return x;}
}}
Insert cell
to_add_to=["one item"]
Insert cell
test_array.forEach(item=>{if (item=="blue"){to_add_to.push("blue")}})
Insert cell
to_add_to
Insert cell
{function countHousedOccurrences(arr) {
let count = 0;

for (let i = 0; i < arr.length; i++) {
if (arr[i] === "housed") {
count++;
}
}

return count;
}

// Example usage:
const myArray = ["housed", "notHoused", "housed", "anotherHoused", "housed"];
const result = countHousedOccurrences(myArray);
console.log(`The word "housed" appears ${result} times in the array.`);}
Insert cell
function countHousedOccurrences(arr) {
let count = 0;

for (let i = 0; i < arr.length; i++) {
if (arr[i] === "housed") {
count++;
}
}

return count;
}
Insert cell
test_array_housed = ["housed", "unhoused", "housed"]
Insert cell
countHousedOccurrences(test_array_housed)
Insert cell
Insert cell
Insert cell
5/4
Insert cell
5%4
Insert cell
3/4
Insert cell
3%4
Insert cell
7%5
Insert cell
5%5
Insert cell
13%5
Insert cell
Insert cell
Insert cell
{
var test_string = ""
if (true){
test_string+="hi ";
}
if (false){
test_string+="also say hi";
}
else if (false){
test_string+=" because the above is an else if, and the if before it triggered, this one won't";
}
else {
test_string+="the last case";
}
return test_string;
}
Insert cell
Insert cell
Insert cell
Insert cell
internet_speeds = [{"city_name":"el paso", "majority_black":true, "internet_speed":"low"},{"city_name":"los angeles", "majority_black":false, "internet_speed":"high"},{"city_name":"new york", "majority_black":true, "internet_speed":"high"}]
Insert cell
internet_speeds.filter(city=>city.majority_black==true&&city.internet_speed=="high")//[0].city_name
Insert cell
internet_speeds.filter(d=>d.majority_black==true||d.internet_speed=="low")
Insert cell
!true
Insert cell
internet_speeds.filter(city_object=>city_object.city_name!="new york")
Insert cell
internet_speeds.filter(function test_func(city_object){return city_object.city_name!="new york"})
Insert cell
internet_speeds.filter(d=>d.majority_black==!true)
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