Skip to content

Commit

Permalink
Alter rank to work on Safari 14 when passed a one-element array
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Mar 9, 2023
2 parents ff49b0c + ce5f3e1 commit ee9a6af
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/rank.js
Expand Up @@ -8,10 +8,10 @@ export default function rank(values, valueof = ascending) {
if (valueof.length !== 2) V = V.map(valueof), valueof = ascending;
const compareIndex = (i, j) => valueof(V[i], V[j]);
let k, r;
Uint32Array
.from(V, (_, i) => i)
.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex))
.forEach((j, i) => {
values = Uint32Array.from(V, (_, i) => i);
// Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
values.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
values.forEach((j, i) => {
const c = compareIndex(j, k === undefined ? j : k);
if (c >= 0) {
if (k === undefined || c > 0) k = j, r = i;
Expand Down

0 comments on commit ee9a6af

Please sign in to comment.