Published
Edited
Aug 15, 2022
1 fork
3 stars
Insert cell
Insert cell
Insert cell
+(12.345678).toFixed(2)
Insert cell
Insert cell
Insert cell
(new Date()).toLocaleDateString([],{
weekday: "long",
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
year: "numeric",
timeZoneName: "long"
})
Insert cell
(new Date()).toLocaleDateString([],{
weekday: "long",
month: "short",
day: "numeric",
})
Insert cell
(new Date("2021-06-23T02:42:27.46+00")).toLocaleTimeString([],{
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 1
// options: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
})

Insert cell
(new Date("2021-06-23T02:42:27.46+00")).toLocaleTimeString()

Insert cell
Insert cell
// Works in node.js
// (str => Buffer.from(str, 'base64').toString('utf-8'))("")
Insert cell
Insert cell
new Date(1627777714000)
Insert cell
Insert cell
window.btoa('Hello, world!')
Insert cell
window.atob('SGVsbG8sIHdvcmxkIQ==')
Insert cell
Insert cell
array_of_just_the_values = [{a:1},{a:3},{a:7},{a:13}].map( row => row.a )
Insert cell
sum_of_array = [1,3,7,13].reduce( ( sum, cur ) => sum + cur )
Insert cell
those_two_combined = [{a:1},{a:3},{a:7},{a:13}].map( row => row.a ).reduce( ( sum, cur ) => sum + cur )
Insert cell
more_complex_object_from_simple_array = [0,1,0,2,0,3].map(d=>{
return { is_zero: d===0, value: d }
})
Insert cell
string_converted_to_code_points = 'HFI!'.split('').map(d=>d.charCodeAt(0))
Insert cell
code_points_converted_to_string = [72,70,73,33].map(d=>String.fromCharCode(d)).join('')
Insert cell
sort_array_based_on_object_properties = [{foo:1,bar:8},{foo:2,bar:4}].sort((a, b) => a.bar - b.bar)
Insert cell
array_of_unique_values_from_an_array = {
const my_array = ["foo", "bar", "foo", "bat", "bat", 1, "1", true];
return [...new Set(my_array)]
}
Insert cell
quick_array_filled_with_range = Array.from({length: 20}, (x, i) => i + 4) // 4 is the floor, if desired
Insert cell
shift_gets_me_the = ["first element","last element"].shift()
Insert cell
pop_gets_me_the = ["first element","last element"].pop()
Insert cell
Insert cell
(6652).toString(2).padStart(16, '0')
Insert cell
Insert cell
( 0b0010011 ^ 0b1111111 ).toString(2) // toString(2) only there so we can see the resulting binary
// could also be written 19 ^ 127
Insert cell
Insert cell
( ~0b0010011 >>> 0 ).toString(2) // toString(2) only there so we can see the resulting binary
Insert cell
Insert cell
map_to_range = (value, in_min, in_max, out_min, out_max) =>
(value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
Insert cell
map_to_range(5, 0, 10, 0, 500)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
"1.19" > "1.2"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more