Skip to content

Instantly share code, notes, and snippets.

@aksnell
Created June 22, 2020 13:35
Show Gist options
  • Save aksnell/2f5d41c3027b0f0565c7212ff68f7293 to your computer and use it in GitHub Desktop.
Save aksnell/2f5d41c3027b0f0565c7212ff68f7293 to your computer and use it in GitHub Desktop.
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