Skip to content

Commit e5c12bc

Browse files
committed
refactoring next_bigger_number
1 parent 25cd374 commit e5c12bc

File tree

1 file changed

+5
-5
lines changed
  • next_bigger_number_with_the_same_digits

1 file changed

+5
-5
lines changed

next_bigger_number_with_the_same_digits/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
function nextBigger(n) {
2-
const arrayWithNumbers = [...String(n)];
3-
let index = arrayWithNumbers.findLastIndex((_, index) => arrayWithNumbers[index] > arrayWithNumbers[index - 1])
2+
const array = [...String(n)];
3+
let index = array.findLastIndex((_, index) => array[index] > array[index - 1])
44
if (index <= 0) return -1;
55

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

88
index = suffle.findIndex(value => value > temp);
9-
arrayWithNumbers[arrayWithNumbers.length - 1] = suffle[index];
9+
array[array.length - 1] = suffle[index];
1010
suffle[index] = temp;
11-
return +arrayWithNumbers.concat(suffle).join('');
11+
return +array.concat(suffle).join('');
1212

1313
// const getMax = number => {
1414
// let array = [];

0 commit comments

Comments
 (0)