The problem statement is, i should replace the any digit below 5 with 0 and any digit 5 and above with 1.
I am trying to reassign values, but it is not affecting, Why?
function fakeBinary(n) {
let numbersArr = n.split('');
numbersArr.forEach(num => {
if(Number(num) < 5) {
num = '0';
} else if(Number(num) >= 5) {
num = '1';
}
});
return numbersArr.join('');
}
console.log(fakeBinary('3457'));
I except the output of 0011
, but the actual output is 3457
.