-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncrementAnyStringTypeNumber.js
More file actions
37 lines (34 loc) · 963 Bytes
/
Copy pathIncrementAnyStringTypeNumber.js
File metadata and controls
37 lines (34 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/// *******In the name of Allah******* ///
function incrementString(a) {
var b = "", c = 0, d = 0, e = 0, f = 0, g = "";
for (var i = 0; i < a.length; i++) {
if (a[i] >= "0" && a[i] <= "9")
c++, b += a[i];
}
if (c) {
d = parseInt(b) + 1;
d = d.toString();
e = d.length;
if (c <= e) {
for (var i = 0; i < a.length; i++) {
if ((a[i] >= "a" && a[i] <= "z") || (a[i] >= "A" && a[i] <= "Z"))
g += a[i];
}
g += d;
}
else {
for (var i = 0; i < a.length; i++) {
if ((a[i] >= "a" && a[i] <= "z") || (a[i] >= "A" && a[i] <= "Z"))
g += a[i];
}
f = c - e;
for (i = 1; i <= f; i++)
g += "0";
g += d;
}
}
else
g += (a + "1");
return g;
}
console.log(incrementString("foobar"));