Skip to content

Commit c872893

Browse files
committed
complete binary:first/1 binary:last/1 TODO
1 parent 0f704aa commit c872893

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • src/javascript/lib/core/erlang_compat

src/javascript/lib/core/erlang_compat/binary.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ function copy(subject, n = 1) {
1010
}
1111

1212
function first(subject) {
13-
//TODO: raise badarg on size 0
13+
if (subject.length == 0) {
14+
throw new Error(`Binary is of length 0`);
15+
}
1416
return at(subject, 0);
1517
}
1618

1719
function last(subject) {
18-
//TODO: raise badarg on size 0
20+
if (subject.length == 0) {
21+
throw new Error(`Binary is of length 0`);
22+
}
1923
return subject.slice(-1);
2024
}
2125

0 commit comments

Comments
 (0)