krasizorbov

Hard Words

Jul 19th, 2020
1,940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let text = input.shift().split(" ");
  3.   let arrayWithWords = input.shift();
  4.   for (let i = 0; i < text.length; i++) {
  5.     if (text[i].includes("_")) {
  6.       let asterix = "";
  7.       if (text[i].lastIndexOf("_") == text[i].length - 1) {
  8.         asterix = "_".repeat(text[i].length);
  9.       } else {
  10.         asterix = "_".repeat(text[i].length - 1);
  11.       }
  12.  
  13.       for (let j = 0; j < arrayWithWords.length; j++) {
  14.         if (asterix.length == arrayWithWords[j].length) {
  15.           text[i] = arrayWithWords[j];
  16.           break;
  17.         }
  18.       }
  19.     }
  20.   }
  21.  
  22.   console.log(text.join(" "));
  23. }
Advertisement
Add Comment
Please, Sign In to add comment