Skip to content

Commit

Permalink
better error for null accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 14, 2021
1 parent 447e695 commit b1d9d3e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function sort(values, ...F) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
values = Array.from(values);
let [f] = F;
if ((F.length === 1 && f.length === 1) || F.length > 1) {
if ((f && f.length === 1) || F.length > 1) {
const index = Uint32Array.from(values, (d, i) => i);
if (F.length > 1) {
F = F.map(f => values.map(f));
Expand Down
5 changes: 3 additions & 2 deletions test/sort-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ it("sort(values) accepts an iterable", () => {
});

it("sort(values) enforces that values is iterable", () => {
assert.throws(() => sort({}), TypeError);
assert.throws(() => sort({}), {name: "TypeError", message: "values is not iterable"});
});

it("sort(values, comparator) enforces that comparator is a function", () => {
assert.throws(() => sort([], {}), TypeError);
assert.throws(() => sort([], {}), {name: "TypeError", message: "compare is not a function"});
assert.throws(() => sort([], null), {name: "TypeError", message: "compare is not a function"});
});

it("sort(values) does not skip sparse elements", () => {
Expand Down

0 comments on commit b1d9d3e

Please sign in to comment.