Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 5 additions & 1 deletion
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‎

Lines changed: 4 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /