Last active
August 29, 2015 13:59
-
-
Save rvbsanjose/10708035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the JavaScript language, have the function DashInsert(num) insert dashes ('-') between each two odd numbers in num. | |
// For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number. | |
// Input = 99946 Output = "9-9-946" | |
// Input = 56730 Output = "567-30" | |
function DashInsert( num ) { | |
var dashI = ''; | |
var nums = ( num ).toString().split( '' ); | |
for ( var i = 0; i < nums.length; i++ ) { | |
if ( ( nums[i] % 2 != 0 ) && ( nums[i+1] % 2 != 0 ) && ( nums[i+1] != undefined ) ) | |
dashI += nums[i] + '-' ; | |
else | |
dashI += nums[i]; | |
} | |
return dashI; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment