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 668d1a2 commit 00e05cdCopy full SHA for 00e05cd
Medium Difficulty/dashInsertII.js
@@ -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