In JavaScript I am trying to solve this code war problem but every time I test it, the test run fails because my return array is returning this over what's expected
Expected:
'[[14,"a"],[1,"b"],[41,"a"],[1,"c"]]'
instead got:
[[14, 'a'], [1, 'b'], [41, 'a'], [1, 'c']]
I noticed that my str.split is returning this as an array ["a", "a", "a", "a", "a", "a", "a", "a", "a", "a", …]
Basically I realized that if I can return the split str into single quotes it might fix the expected return how can I go about this.
var compress = function(str) {
let strArr = str.split('')
let counter = 1
let rtnArr = []
console.log(strArr)
const strMap = strArr.map((val, idx) => {
if (val === (strArr[idx + 1])) counter += 1
else {
rtnArr.push([counter, val])
counter = 1
}
})
// console.log(rtnArr)
return rtnArr
}