Platform
Resources
Pricing
Sign in
Get started
David Hall
Workspace
Fork
Published
By
David Hall
Edited
Jul 27, 2019
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function
test
(
expected
,
actual
)
{
if
(
expected
===
actual
)
{
return
actual
+
" (ok)"
;
}
else
{
return
"("
+
typeof
actual
+
") "
+
actual
+
" <= FAILED: (expected ("
+
typeof
expected
+
") "
+
expected
+
")"
;
}
}
Insert cell
function
abs
(
n
)
{
return
signum
(
n
)
==
-
1
?
negate
(
n
)
:
n
;
}
Insert cell
function
isBig
(
n
)
{
return
(
typeof
n
)
==
"bigint"
;
}
Insert cell
function
isNumber
(
n
)
{
return
(
typeof
n
)
==
"number"
;
}
Insert cell
function
isOne
(
n
)
{
return
n
==
1
;
}
Insert cell
function
isZero
(
n
)
{
return
n
==
0
;
}
Insert cell
function
negate
(
n
)
{
return
-
n
;
}
Insert cell
function
negOne
(
n
)
{
return
negate
(
one
(
n
)
)
;
}
Insert cell
function
one
(
n
)
{
return
isBig
(
n
)
?
1n
:
1
;
}
Insert cell
function
signum
(
n
)
{
return
n
==
0
?
0
:
n
<
0
?
-
1
:
1
;
}
Insert cell
function
zero
(
n
)
{
return
isBig
(
n
)
?
0n
:
0
;
}
Insert cell
Insert cell
function
eulerTotient
(
n
)
{
var
result
=
n
;
for
(
var
i
=
2
;
i
*
i
<=
n
;
i
++
)
{
if
(
n
%
i
==
0
)
result
-=
result
/
i
;
while
(
n
%
i
==
0
)
{
n
/=
i
;
}
}
if
(
n
>
1
)
{
result
-=
result
/
n
;
}
return
result
;
}
Insert cell
function
isPowerOfTwo
(
n
)
{
return
(
n
!=
0
)
&&
(
(
n
&
-
n
)
==
n
)
;
}
Insert cell
Insert cell
function
getRandomNumber
(
limit
=
100
)
{
return
Math
.
floor
(
(
Math
.
random
(
)
-
0.5
)
*
limit
)
;
}
Insert cell
function
getIdentityMatrix
(
size
=
3
)
{
var
rows
=
[
]
;
for
(
let
r
=
0
;
r
<
size
;
r
++
)
{
var
cols
=
[
]
;
for
(
let
c
=
0
;
c
<
size
;
c
++
)
{
cols
.
push
(
r
==
c
?
1
:
0
)
;
}
rows
.
push
(
cols
)
;
}
return
rows
;
}
Insert cell
function
getAdditionTable
(
size
=
3
)
{
var
rows
=
[
]
;
for
(
let
r
=
0
;
r
<
size
;
r
++
)
{
var
cols
=
[
]
;
for
(
let
c
=
0
;
c
<
size
;
c
++
)
{
cols
.
push
(
r
+
c
)
;
}
rows
.
push
(
cols
)
;
}
return
rows
;
}
Insert cell
function
getMultiplicationTable
(
size
=
3
)
{
var
rows
=
[
]
;
for
(
let
r
=
0
;
r
<
size
;
r
++
)
{
var
cols
=
[
]
;
for
(
let
c
=
0
;
c
<
size
;
c
++
)
{
cols
.
push
(
(
r
+
1
)
*
(
c
+
1
)
)
;
}
rows
.
push
(
cols
)
;
}
return
rows
;
}
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bigNote
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
test
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
abs
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isBig
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isNumber
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isOne
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isZero
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
negate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
negOne
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
one
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
signum
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
zero
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
eulerTotient
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isPowerOfTwo
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getRandomNumber
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getIdentityMatrix
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getAdditionTable
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getMultiplicationTable
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML