Use the parseInt Function with a Radix


#1

Tell us what’s happening:

Your code so far


function convertToInteger(str) {
var a=parseInt("",2);
return a;
if(str=="")
return NaN;
}

convertToInteger("10011");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.one/javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix


#2
  1. 题目是要把传入的 str 转换成十进制,但你写死了空字符串 ""
  2. 不光在空字符串的时候需要返回 NaN,还有其他情况。参考左边的测试用例