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 6c93d8c

Browse files
committed
update: test cases, prettier rc file for cross IDE code format
1 parent fee46b9 commit 6c93d8c

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

‎.prettierrc.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 2
7+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { composeHighest, compare } = require('.');
2+
3+
/**
4+
* Test cases
5+
* [3, 6, 0, 9] -> 9630
6+
* [60, 548] -> 60548
7+
* [1, 34, 3, 98, 9, 76, 45, 4] -> 998764543431
8+
*/
9+
10+
describe('Compose Largest Number', () => {
11+
describe('The main function returning the Highest NUmber', () => {
12+
it('Should return 9630 for `[3, 6, 0, 9]`', () => {
13+
expect(composeHighest([3, 6, 0, 9])).toEqual(9630);
14+
});
15+
16+
it('Should return 60548 for `[60, 548]`', () => {
17+
expect(composeHighest([60, 548])).toEqual(60548);
18+
});
19+
20+
it('Should return 998764543431 for `[1, 34, 3, 98, 9, 76, 45, 4]`', () => {
21+
expect(composeHighest([1, 34, 3, 98, 9, 76, 45, 4])).toEqual(998764543431);
22+
});
23+
});
24+
25+
describe('Testing `compare()`', () => {
26+
it('Should return [60, 548] instead of [548, 60]', () => {
27+
expect([60, 548].sort(compare)).toEqual([60, 548]);
28+
});
29+
30+
it('Should return [9, 81, 548] instead of [548, 81, 9]', () => {
31+
expect([548, 9, 81].sort(compare)).toEqual([9, 81, 548]);
32+
});
33+
});
34+
});

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
/** At first glance, the below solution may seem the answer */
11-
const hightestNumber = Number([60, 548].sort((a, b) => b - a).join(""));
11+
// const hightestNumber = Number([60, 548].sort((a, b) => b - a).join(''));
1212

1313
/** The above will fail for test case 2 & 3 */
1414

@@ -22,14 +22,16 @@ function compare(a, b) {
2222
/** final function */
2323
function composeHighest(arr) {
2424
if (!arr || !Array.isArray(arr)) {
25-
throw new Error("Invalid array/missing argument");
25+
throw new Error('Invalid array/missing argument');
2626
}
2727

28-
return Number(arr.sort(compare).join(""));
28+
return Number(arr.sort(compare).join(''));
2929
}
3030

3131
/** tests */
3232

33-
console.log(composeHighest([3, 6, 0, 9]) === 9630);
34-
console.log(composeHighest([60, 548]) === 60548);
35-
console.log(composeHighest([1, 34, 3, 98, 9, 76, 45, 4]) === 998764543431);
33+
// console.log(composeHighest([3, 6, 0, 9]) === 9630);
34+
// console.log(composeHighest([60, 548]) === 60548);
35+
// console.log(composeHighest([1, 34, 3, 98, 9, 76, 45, 4]) === 998764543431);
36+
37+
module.exports = { composeHighest, compare };

0 commit comments

Comments
(0)

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