Convert "Zero" and "One" to 0 and 1 in javaScript?
Create a function that takes a string as an argument. The function must return a string containing 1s and 0s based on the string argument's words
1 Answer
ok, it's very easy to Convert "Zero" and "One" to 0 and 1 in javaScript
look to this function
const textToNumberBinary = str => {
const cleanStr = str
.replace(/zero/gi, '0')
.replace(/one/gi, '1')
.replace(/[^01]/g, '');
const strLength = Math.floor(cleanStr.length / 8) * 8;
return cleanStr.slice(0, strLength);
}
answer Link