[刷題紀錄] Codewars-8kyu
TL;DR
將刷過的題目給記錄起來
String
將數字轉換為字串
url
:https://www.codewars.com/kata/5265326f5fda8eb1160004c8/train/javascriptdescription
:We need a function that can transform a number (integer) into a string. What ways of achieving this do you know? Examples (input --> output):123 --> "123"
999 --> "999"
-100 --> "-100"
After practice
- 我的答案
- 最佳解
- 知識點
- 其他補充
function numberToString(num) {
return num.toString();
}
function numberToString(num) {
return num.toString();
}
也有其他的解法如下
function numberToString(num) {
// Return a string of the number here!
return String(num);
}
//or
function numberToString(num) {
return ''+num;
}
//or
const numberToString = num => `${num}`;