Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = "зебра, ребра";
- let firstWord = input.split(", ")[0];
- let secondWord = input.split(", ")[1];
- let isThereEqualSymbol = false;
- let indexOfTheFirstEqualSymbol = -1;
- let indexToPrintFirstWord = -1;
- for (let i = 0; i < firstWord.length; i++) {
- for(let j = 0; j < secondWord.length; j++) {
- if(secondWord[j] === firstWord[i]) {
- isThereEqualSymbol = true;
- indexOfTheFirstEqualSymbol = i;
- indexToPrintFirstWord = j;
- i = firstWord.length;
- break;
- }
- }
- }
- let matrix = new Array(secondWord.length);
- for (let i = 0; i < secondWord.length; i++) {
- matrix[i] = new Array(firstWord.length);
- }
- if(isThereEqualSymbol) {
- for(let row = 0; row < matrix.length; row++) {
- for(let col = 0; col < matrix[row].length; col++) {
- if(col == indexOfTheFirstEqualSymbol) {
- matrix[row][col] = secondWord[row];
- } else if(row == indexToPrintFirstWord) {
- matrix[row][col] = firstWord[col];
- }else {
- matrix[row][col] = " ";
- }
- }
- }
- }else {
- console.log("There's no equal elements");
- return;
- }
- console.log(matrix);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement