forked from jimmyislive/coderbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash-insert-ii.js
More file actions
32 lines (24 loc) · 768 Bytes
/
dash-insert-ii.js
File metadata and controls
32 lines (24 loc) · 768 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
function DashInsertII(num) {
var num_str = num + '',
str = '';
for (var i = 0; i < num_str.length - 1; i++) {
var current_digit = parseInt(num_str.charAt(i)),
next_digit = parseInt(num_str.charAt(i + 1));
if (!current_digit || !next_digit) {
str += current_digit;
} else if ((current_digit % 2) && (next_digit % 2)) {
//odd number
str += current_digit + "-";
} else if ((current_digit % 2 === 0) && (next_digit % 2 === 0)) {
//even number
str += current_digit + "*";
} else {
str += current_digit;
}
}
str += next_digit;
return str;
}
// this call is needed to test your function
// keep this when you submit your code
DashInsertII(num)