decode(str) { const result = [] let i = 0 while (i < str.length) { const delimeter = str.indexOf('#', i) const length = str.substring(i, delimeter) const word = str.substring(delimeter + 1, delimeter + parseInt(length) + 1) result.push(word) // Move past: length digits + '#' + word i += length.length + 1 + parseInt(length) } return result }
const word = str.substring(delimeter + 1, delimeter + 1 + parseInt(length))
0123456789 4#neet11#prashantbas
i += length.length + 1 + word.length
Written by Brain Dump