Skip to content Skip to sidebar Skip to footer

One Index Is Dependent On Another Index In Java Script

I'm making a function for a moving window design self-paced reading experiment where a sentence is input and a function replaces all letters with dashes. The participant then click

Solution 1:

If I understood correctly, this is what you are looking or, right?

functionreplaceWithdash(sentenceList, currentWordNumber) {
    const regions = sentenceList.split(",")
    const sigil = regions.map(s => s.replaceAll(/[^\s]/g, "-"))
    if (currentWordNumber !== undefined) {
        sigil.splice(currentWordNumber, 1, regions[currentWordNumber])
    }
    return sigil.join("")
}

str = "The dog, ate, the food"console.log(replaceWithdash(str))
//"--- --- --- --- ----"console.log(replaceWithdash(str, 0))
//"The dog --- --- ----"console.log(replaceWithdash(str, 1))
//"--- --- ate --- ----"console.log(replaceWithdash(str, 2))
// "--- --- --- the food"

Post a Comment for "One Index Is Dependent On Another Index In Java Script"