Question Bank

JavaScript Square and Join Digits: Two Approaches Quiz

Difficulty: Medium

Two seeded ways to square each digit of an integer and concatenate the results (string split with map and join, plus a while-loop modulo extraction), with two companions on negative numbers and on returning a string.

Question Bank
/

JavaScript Square and Join Digits: Two Approaches Quiz

JavaScript Square and Join Digits: Two Approaches Quiz

Two seeded ways to square each digit of an integer and concatenate the results (string split with map and join, plus a while-loop modulo extraction), with two companions on negative numbers and on returning a string.

Question Bank
Medium
JavaScript
4 questions
quiz
math
strings
array-manipulation-patterns

489 views

14

Implement squareDigit(num) using string conversion: split the number into characters, square each digit, join them back together, and return the result as a Number.

Examples

Example 1:

Input: squareDigit(57)
Output: 2549
Explanation: 5*5 = 25 and 7*7 = 49, concatenating gives '2549', and Number('2549') is 2549.