numberToString.js (8kyu 21)

Codewars 알고리즘 풀이


Description

  • We need a function that can transform a number into a string.
    • 숫자를 문자열로 변환한다.



Solution 01

function numberToString(num) {
  return '' + num;
}

numberToString(1234);                      // 1234
console.log(typeof numberToString(1234));  // string


Solution 02

function numberToString(num) {
  return num.toString();
}

numberToString(1234);                      // 1234
console.log(typeof numberToString(1234));  // string


Solution 03

function numberToString(num) {
  return String(num);
}

numberToString(1234);                      // 1234
console.log(typeof numberToString(1234));  // string