Platform
Resources
Pricing
Sign in
Get started
Nikolaus Piccolotto
“Any problem in computer science can be solved with another level of misdirection.” — David Wheeler
Workspace
Fork
Published
By
Nikolaus Piccolotto
Edited
Aug 3, 2022
Insert cell
Insert cell
ntile
(
[
0
,
1
,
2
,
3
,
undefined
,
4
,
5
,
true
,
6
,
null
,
7
,
8
,
NaN
,
9
,
10
]
)
Insert cell
function
ntile
(
arr
,
n
=
4
)
{
const
ps
=
d3
.
range
(
1
,
n
)
.
map
(
(
x
)
=>
x
/
n
)
;
const
pq
=
ps
.
map
(
(
x
)
=>
d3
.
quantile
(
arr
,
x
)
)
;
return
arr
.
map
(
(
x
)
=>
{
for
(
const
[
i
,
cut
]
of
pq
.
entries
(
)
)
{
if
(
!
Number
.
isFinite
(
x
)
)
{
return
NaN
;
}
if
(
x
<=
cut
)
{
return
i
+
1
;
}
}
return
n
;
}
)
;
}
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ntile
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML