Skip to content

Commit

Permalink
Fix TypeError when sorting BigInt and Numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
timagixe authored and tshemsedinov committed Jan 11, 2023
1 parent ebe73ae commit 4d9db53
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion JavaScript/9-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ console.log();
const array1 = [-2, 7, 1n, 3, -2n, 8n, 5, -4n];
console.log(array1);
console.log(array1.sort());
console.log(array1.sort((a, b) => BigInt(a) - BigInt(b)));
console.log(array1.sort((a, b) => {
const biA = BigInt(a);
const biB = BigInt(b);
if (biA < biB) return -1;
if (biA > biB) return 1;
return 0;
}));
console.log();

// https://github.com/tc39/proposal-bigint

0 comments on commit 4d9db53

Please sign in to comment.