Skip to content

Commit 7952835

Browse files
dimfeldFil
authored andcommitted
Alter rank to work on Safari 14 when passed a one-element array
2 parents ff49b0c + ce5f3e1 commit 7952835

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/rank.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export default function rank(values, valueof = ascending) {
88
if (valueof.length !== 2) V = V.map(valueof), valueof = ascending;
99
const compareIndex = (i, j) => valueof(V[i], V[j]);
1010
let k, r;
11-
Uint32Array
12-
.from(V, (_, i) => i)
13-
.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex))
14-
.forEach((j, i) => {
11+
values = Uint32Array.from(V, (_, i) => i);
12+
// Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
13+
values.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
14+
values.forEach((j, i) => {
1515
const c = compareIndex(j, k === undefined ? j : k);
1616
if (c >= 0) {
1717
if (k === undefined || c > 0) k = j, r = i;

0 commit comments

Comments
 (0)