Open zwhu opened 7 years ago
这是一篇水文,老板给面试同学出的笔试题,顺手练一下
function toBinary(n) { function toBinaryIter(n, s) { if(n === 0) { return s || '0' } var a = n / 2 , b = n % 2 return toBinaryIter(a|0, b+s) } return toBinaryIter(n, '') } toBinary(0) === (0).toString(2) toBinary(1) === (1).toString(2) toBinary(3) === (3).toString(2) toBinary(10) === (10).toString(2) toBinary(101) === (101).toString(2)
这是一篇水文,老板给面试同学出的笔试题,顺手练一下