Skip to content
Advertisement

how to replace some character with certain repeting regex

this is the log

JavaScript

the output must be====>|~~X~~~X2~2~~22~2~~~~2~~~|

here the code i’ve try:

JavaScript

how to make /2/g just replace certain repeating

i wanna make code above same function with this

function duckShoot(ammo, aim, ducks) {

JavaScript

}

Advertisement

Answer

JavaScript

or you can keep the ‘old’ replace with the regex

JavaScript

whereas

JavaScript

is a simple function decreasing the counter and returning an ‘X’ or keep the o(riginal)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement