The task, the function takes a numeric string, if the first number in the string is less than five, replace it with 0, if more than 1.
The result of the work should be:
fakeBin('45385593107843568') --> '01011110001100111' Here is my code, I can not figure out why it returns, except for 0 and 1, also the original values. How to fix it ?
function fakeBin(text){ var result = ''; for (var i = 0; i < text.length; i++) { if (text[i] < 5) { result += 0 + " "; } else { result += 1 + " "; } result += text[i] + " "; } return result.slice(0, result.length-1); } fakeBin('16');