Created
June 12, 2017 18:40
-
-
Save BeKnowDo/73b804978db4541c0af1c63a5345a91d to your computer and use it in GitHub Desktop.
Square Digits
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
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