Please Help! Algorithms

Given a string s consisting of Latin letters and digits, change each of its digit to the corresponding number of ones.

Example

For s = "abc5bc3", the output should be s = "abc11111bc111".

Anyone to solve this problem for me would be appreciated, Thanks.

Hi!

Is there a specific question you have about the algorithm? It sounds like you’re asking for someone to write it for you, in which case you’re not very likely to find someone to do that for you I’m afraid :slightly_smiling_face:

So I am finding it difficult to convert the numbers within the string into ones.

I tried retrieving only the numbers within the strings.

This is my code:

function solution (s) {
    let output = []
    let sArr = s.split('')
    sArr.map(element => {
        if (parseInt(element)) {
            console.log(element)
            output.push(Number(element))
        }
    })
    return output
}

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.