Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 908 Bytes

digit-digit.md

File metadata and controls

33 lines (24 loc) · 908 Bytes

Digit*Digit 7 Kyu

LINK TO THE KATA - MATHEMATICS FUNDAMENTALS

Description

Welcome. In this kata, you are asked to square every digit of a number and concatenate them.

For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. (81-1-1-81)

Example #2: An input of 765 will/should return 493625 because 72 is 49, 62 is 36, and 52 is 25. (49-36-25)

Note: The function accepts an integer and returns an integer.

Happy Coding!

Solution

const squareDigits = num => {
  const strNum = num.toString()
  const strArray = strNum.split('')
  const powNumArray = strArray.map(str => {
    const num = Number(str)
    return num * num
  })
  return Number(powNumArray.join(''))
}