Tell us what’s happening:
Hi, everyone,
I’m working to better understand the implications of this challenge and solving it bit by bit and I came across something odd.
My question is, how can console.log(strToArr[4].match(regexTest).length); return 1 when that string (00100111) begins with two 0’s?
Thank you!
Your code so far
function binaryAgent(str) {
var strToArr = str.split(' ');
var numbers = [];
var regexTest = /^0+/;
console.log(strToArr[4].match(regexTest).length);
var eliminateZeroes = function(array, newArray) {
for (var i = 0; i < array.length; i++) {
if (array[i].match(regexTest) != "") {
newArray.push(array[i].slice(array[i].match(regexTest).length));
}
}
}
eliminateZeroes(strToArr, numbers);
console.log(numbers);
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.
Link to the challenge: