Created
November 26, 2020 14:11
-
-
Save Aabill/028d2e4f06310191c412ef905a4e9eae to your computer and use it in GitHub Desktop.
Dictionary and Matrix JS
This file contains hidden or 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
console.log("Matrix and Dictionary"); | |
function Find(dictionary_yords, matrix_yords) { | |
if (matrix_yords.length < 6) | |
{ | |
let result = []; | |
let matrix_vertical = []; | |
for(let i = 0; i < matrix_string_array.length; i++) | |
{ | |
let newString = ''; | |
matrix_yords.forEach((el) => { | |
// Arrange Matrix Vertically. | |
newString += el[i]; | |
}) | |
// Push NewString to matrix_vertical array. | |
matrix_vertical.push(newString); | |
} | |
dictionary_yords.forEach((el) => { | |
matrix_yords.forEach((Element) => { | |
// Check if dictionary word exists horizontally from top to bottom in matrix. | |
if (Element.includes(el)) | |
{ | |
console.log('The word ' + el + ' is found horizontally in row ' + Number(matrix_yords.indexOf(Element)+1) + '.'); | |
result.push(el); | |
} | |
}) | |
matrix_vertical.forEach((Element) => { | |
// Check if dictionary word exists vertically from top to bottom in matrix. | |
if (Element.includes(el)) | |
{ | |
console.log('The word ' + el + ' is found vertically in column ' + Number(matrix_vertical.indexOf(Element)+1) + '.'); | |
result.push(el); | |
} | |
}) | |
}) | |
return result; | |
} | |
} | |
let matrix_string_array = ['abcdc', 'fgwio', 'chill', 'pqnsd', 'uvdxy']; | |
let dictionary = ['chill', 'wind', 'snow', 'cold']; | |
let result = Find(dictionary, matrix_string_array); | |
console.log('Result Contains:'); | |
console.log(result); | |
Author
Aabill
commented
Nov 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment