Skip to content

Commit 00e05cd

Browse files
author
Kyle Maune
committed
added dash insert II solution
1 parent 668d1a2 commit 00e05cd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Medium Difficulty/dashInsertII.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// coderbyte solution for dash insert II
2+
// splashinn
3+
4+
function dashInsertII(num) {
5+
var str = "" + num;
6+
var result = new Array(str.length);
7+
for (var i = 0; i < str.length; i++) {
8+
var digit = parseInt(str[i]);
9+
if ((str[i + 1] !== undefined) && digit % 2 !== 0 && parseInt(str[i + 1]) % 2 !== 0) {
10+
result[i] = str[i] + "-";
11+
} else if ((str[i + 1] !== undefined) && digit % 2 === 0 && parseInt(str[i + 1]) % 2 === 0 &&
12+
digit !== 0 && parseInt(str[i + 1]) !== 0) {
13+
result[i] = str[i] + "*";
14+
} else {
15+
result[i] = str[i];
16+
}
17+
}
18+
return result.join("");
19+
}

0 commit comments

Comments
 (0)