vladovip

JavaScript_ replace char / word

Dec 26th, 2021
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(firstWord, missingChar, secondWord) {
  2.     let newWord = "";
  3.  
  4.     for (let i = 0; i < firstWord.length; i++) {
  5.  
  6.         if (firstWord[i] === '_') {
  7.             newWord += missingChar;
  8.         } else {
  9.             newWord += firstWord[i];
  10.         }
  11.     }
  12.  
  13.     if (newWord == secondWord) {
  14.         console.log("Matched");
  15.     } else {
  16.         console.log("Not Matched");
  17.     }
  18.  
  19.  
  20. }
  21. solve('Str_ng', 'I', 'Strong');
  22.  
  23.  
  24. /* You will receive 3 parameters (string, char, string).
  25. The first string will be a word with a missing char replaced with an underscore '_'
  26. You have to replace the character with the missing part (underscore)
  27. from the first string and compare the result with the second string.
  28. If they are equals you should print "Matched", otherwise print "Not Matched".
  29. */
Advertisement
Add Comment
Please, Sign In to add comment