dimytar11

Untitled

Oct 27th, 2021
725
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = "зебра, ребра";
  2.  
  3. let firstWord = input.split(", ")[0];
  4. let secondWord = input.split(", ")[1];
  5.  
  6. let isThereEqualSymbol = false;
  7.  
  8. let indexOfTheFirstEqualSymbol = -1;
  9. let indexToPrintFirstWord = -1;
  10.  
  11. for (let i = 0; i < firstWord.length; i++) {
  12.     for(let j = 0; j < secondWord.length; j++) {
  13.         if(secondWord[j] === firstWord[i]) {
  14.             isThereEqualSymbol = true;
  15.             indexOfTheFirstEqualSymbol = i;
  16.             indexToPrintFirstWord = j;
  17.             i = firstWord.length;
  18.             break;
  19.         }
  20.     }
  21. }
  22.  
  23. let matrix = new Array(secondWord.length);
  24.  
  25. for (let i = 0; i < secondWord.length; i++) {
  26.     matrix[i] = new Array(firstWord.length);
  27. }
  28.  
  29. if(isThereEqualSymbol) {
  30.  
  31.     for(let row = 0; row < matrix.length; row++) {
  32.         for(let col = 0; col < matrix[row].length; col++) {
  33.             if(col == indexOfTheFirstEqualSymbol) {
  34.                 matrix[row][col] = secondWord[row];
  35.             } else if(row == indexToPrintFirstWord) {
  36.                 matrix[row][col] = firstWord[col];
  37.             }else {
  38.                 matrix[row][col] = " ";
  39.             }
  40.         }
  41.     }
  42.  
  43. }else {
  44.     console.log("There's no equal elements");
  45.     return;
  46. }
  47.  
  48. console.log(matrix);
RAW Paste Data