We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5963760 commit c555454Copy full SHA for c555454
Medium Difficulty/permutationStep2.js
@@ -0,0 +1,36 @@
1
+// coderbyte solution for permutation step
2
+// splashinn
3
+
4
+function permutationStep(num) {
5
6
+ var concat = function (arr) {
7
+ var s = '';
8
+ for (var i = 0; i < arr.length; i++) {
9
+ s += arr[i];
10
+ }
11
12
+ return s;
13
+ };
14
15
+ var equalPerm = function (a, b) {
16
+ a = (a + '').split('');
17
+ b = (b + '').split('');
18
+ a.sort();
19
+ b.sort();
20
+ return concat(a) == concat(b);
21
22
23
+ var f = (num + '').split('');
24
+ f.sort(function (a, b) { return a < b; });
25
26
+ if (concat(f) == num) {
27
+ return -1;
28
29
30
+ for (var i = num + 1; ; i++) {
31
+ if (equalPerm(num, i)) {
32
+ return i;
33
34
35
+ return equalPerm(123, 321);
36
+}
0 commit comments