I'm confused about why array.join("") is not working properly in this function.
If the letter is a-m it will show 0 and the otherwise is 1
convertBinary("house") ➞ "01110"
function convertBinary(str) {
var jack=str.split("")
return jack.map(function(e) {
var array=[]
if(e.match(/[abcdefghijklm]/g)) {
array.push(0)
} else {
array.push(1)
}
return array.join("");
})
}
Where did I go wrong.
return 0orreturn 1. The map function will return the new array, so you should addjoin("")to the result of the map function. (NB - Your array inside the function inside map is not necessary - your code in this function just results in "0" or "1")mapalways returns an array,array.join(). Read aboutArray.map().return str.split("").map(c => +!/[a-m]/g.test(c)).join("");