Created
June 22, 2020 13:35
-
-
Save aksnell/2f5d41c3027b0f0565c7212ff68f7293 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function insertDash(num) { | |
return num.toString() | |
.split('') | |
.reduce((acc, n, i, array) => { | |
return acc += (i > 0 && parseInt(array[i]) % 2 != 0 && parseInt(array[i-1]) % 2 !== 0) ? `-${n}` : n | |
}, '') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment