This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myReplace(str, before, after ) { | |
/* | |
* 1. Check if the old word has its first letter in a capital or not: | |
* - if yes : return the new word with a capital on the first letter | |
* - if no : return the new word as it is | |
*/ | |
let newStr = /^[A-Z]/.test( before[0] ) | |
? `${ after.substring( 0, 1 ).toUpperCase()}${ after.substring( 1 ) }` | |
: after; |