Skip to content

Instantly share code, notes, and snippets.

@BeKnowDo
Created June 12, 2017 18:40
Show Gist options
  • Save BeKnowDo/73b804978db4541c0af1c63a5345a91d to your computer and use it in GitHub Desktop.
Save BeKnowDo/73b804978db4541c0af1c63a5345a91d to your computer and use it in GitHub Desktop.
Square Digits
function squareDigits(num) {
//may the code be with you
let number = num.toString(),
if (typeof number === 'string') {
let numberArray = number.split(''),
newArray = []
numberArray.forEach(function(item){
if(new Number(item)) {
let stringToNumberConvert = new Number(item),
squaredDigit = new Number(stringToNumberConvert * stringToNumberConvert)
newArray.push(squaredDigit)
}
})
return newArray
}
}
squareDigits(132456)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment