Skip to content

Commit bdbded9

Browse files
committed
update: test for throw, fix in TOC
1 parent daea20d commit bdbded9

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

TOC.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Table of Contents
1+
# Table of Contents
22

3-
### Data Structures
3+
## Data Structures
44

55
- [Singly Linked List](src/_DataStructures_/LinkedList)
66

src/_Problems_/compose-largest-number/compose-largest.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { composeHighest, compare } = require('.');
1+
const { composeHighest, compare, ErrorMessage } = require('.');
22

33
/**
44
* Test cases
@@ -9,6 +9,10 @@ const { composeHighest, compare } = require('.');
99

1010
describe('Compose Largest Number', () => {
1111
describe('The main function returning the Highest NUmber', () => {
12+
it('Should throw error for invalid argument', () => {
13+
expect(() => composeHighest('abcd')).toThrow(ErrorMessage);
14+
});
15+
1216
it('Should return 9630 for `[3, 6, 0, 9]`', () => {
1317
expect(composeHighest([3, 6, 0, 9])).toEqual(9630);
1418
});

src/_Problems_/compose-largest-number/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ function compare(a, b) {
1919
return x > y ? -1 : 1;
2020
}
2121

22+
const ErrorMessage = 'Invalid array/missing argument';
23+
2224
/** final function */
2325
function composeHighest(arr) {
2426
if (!arr || !Array.isArray(arr)) {
25-
throw new Error('Invalid array/missing argument');
27+
throw new Error(ErrorMessage);
2628
}
2729

2830
return Number(arr.sort(compare).join(''));
@@ -34,4 +36,4 @@ function composeHighest(arr) {
3436
// console.log(composeHighest([60, 548]) === 60548);
3537
// console.log(composeHighest([1, 34, 3, 98, 9, 76, 45, 4]) === 998764543431);
3638

37-
module.exports = { composeHighest, compare };
39+
module.exports = { composeHighest, compare, ErrorMessage };

0 commit comments

Comments
 (0)