Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems #158

Merged
merged 8 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: test for throw, fix in TOC
  • Loading branch information
ashokdey committed Nov 13, 2019
commit bdbded9fd6b56cb88e62176a8cc2ea416db357b5
4 changes: 2 additions & 2 deletions TOC.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Table of Contents
# Table of Contents

### Data Structures
## Data Structures

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { composeHighest, compare } = require('.');
const { composeHighest, compare, ErrorMessage } = require('.');

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

describe('Compose Largest Number', () => {
describe('The main function returning the Highest NUmber', () => {
it('Should throw error for invalid argument', () => {
expect(() => composeHighest('abcd')).toThrow(ErrorMessage);
});

it('Should return 9630 for `[3, 6, 0, 9]`', () => {
expect(composeHighest([3, 6, 0, 9])).toEqual(9630);
});
Expand Down
6 changes: 4 additions & 2 deletions src/_Problems_/compose-largest-number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ function compare(a, b) {
return x > y ? -1 : 1;
}

const ErrorMessage = 'Invalid array/missing argument';

/** final function */
function composeHighest(arr) {
if (!arr || !Array.isArray(arr)) {
throw new Error('Invalid array/missing argument');
throw new Error(ErrorMessage);
}

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

module.exports = { composeHighest, compare };
module.exports = { composeHighest, compare, ErrorMessage };