fork download
  1. function replaceOddNumbersWithRR(str) {
  2. // Use a regular expression to find all odd numbers (\d*[13579]\d*) in the string
  3. // and replace them with the text "rr"
  4. return str.replace(/\b\d*[13579]\d*\b/g, "rr");
  5. }
  6.  
  7. // Test the function
  8. var input = "I have 12 cars, 11 of which are 89 years old";
  9. var result = replaceOddNumbersWithRR(input);
  10. console.log(result); // Outputs: "I have 12 cars, rr of which are rr years old"
  11.  
Success #stdin #stdout 0.03s 16604KB
stdin
Standard input is empty
stdout
I have rr cars, rr of which are rr years old