Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square Every Digit #6

Open
rafaelkendrik opened this issue Jan 19, 2021 · 0 comments
Open

Square Every Digit #6

rafaelkendrik opened this issue Jan 19, 2021 · 0 comments

Comments

@rafaelkendrik
Copy link
Owner

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.

Note: The function accepts an integer and returns an integer

function squareDigits(num){
  if (!Number.isInteger(num)) {
    return new Error('Only supports integers')
  }
  
  return Number(
    Array
      .from(String(num))
      .map(n => n * n)
      .join('')
  )
}

https://www.codewars.com/kata/546e2562b03326a88e000020/train/javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant