Convert a String to a Number! : codewars javascript

front·2022년 11월 9일

kata

Note: This kata is inspired by Convert a Number to a String!. Try that one too.

Description
We need a function that can transform a string into a number. What ways of achieving this do you know?

Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number.

Examples
"1234" --> 1234
"605"  --> 605
"1405" --> 1405
"-7" --> -7

my answer

const stringToNumber = function(str){
  // put your code here
  var result = Number(str)
  return result;
}

best answer

var stringToNumber = function(str){
  return parseInt(str);
}
profile
그냥 하기

0개의 댓글