Skip to content

Commit f8fcd37

Browse files
committed
refactoring next_bigger_number
1 parent e5c12bc commit f8fcd37

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

next_bigger_number_with_the_same_digits/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function nextBigger(n) {
33
let index = array.findLastIndex((_, index) => array[index] > array[index - 1])
44
if (index <= 0) return -1;
55

6-
const [suffle, temp] = [array.splice(index).sort(), array[array.length - 1]];
6+
const [suffle, temp] = [array.splice(index).sort(), array.at(-1)];
77

88
index = suffle.findIndex(value => value > temp);
99
array[array.length - 1] = suffle[index];

next_bigger_number_with_the_same_digits/main.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ describe('The next bigger number', () => {
1313
expect(nextBigger(2017)).toBe(2071)
1414
})
1515

16+
test('the next bigger number of 2314 is 2341', () => {
17+
expect(nextBigger(2314)).toBe(2341)
18+
})
19+
1620
test('the next bigger number of 144 is 414', () => {
1721
expect(nextBigger(144)).toBe(414)
1822
})
@@ -25,6 +29,10 @@ describe('The next bigger number', () => {
2529
expect(nextBigger(643220)).toBe(-1)
2630
})
2731

32+
test('the next bigger number of 7139401 is 7139410', () => {
33+
expect(nextBigger(7139401)).toBe(7139410)
34+
})
35+
2836
test('the next bigger number of 29977540 is 40257799', () => {
2937
expect(nextBigger(29977540)).toBe(40257799)
3038
})

0 commit comments

Comments
 (0)