Skip to content

Instantly share code, notes, and snippets.

@rmdhfz
Created January 10, 2022 07:24
Show Gist options
  • Save rmdhfz/ebcfee789fb5b581346e665d352e1b95 to your computer and use it in GitHub Desktop.
Save rmdhfz/ebcfee789fb5b581346e665d352e1b95 to your computer and use it in GitHub Desktop.
Technical Test - Pre Assessment Software Engineer (Jr. Back End) Ultra Voucher
const words = ["cook", "save", "taste", "aves", "vase", "state", "map"];
const findAnagrams = (words) => {
const uniqueAnagrams = [words[0]],
combinedAnagrams = [words[0]];
for (let i = 1; i < words.length; i++) {
const word = words[i];
let matched = false;
for (let j = 0; j < uniqueAnagrams.length; j++) {
const testWord = uniqueAnagrams[j];
let matchCount = 0;
for (let k = 0; k < word.length; k++) {
const letter = word[k],
match = testWord.includes(letter);
match && matchCount++;
}
if (matchCount === testWord.length) {
matched = true;
Array.isArray(combinedAnagrams[j])
? combinedAnagrams[j].push(word)
: (combinedAnagrams[j] = [testWord, word]);
break;
}
}
if (!matched) {
combinedAnagrams.push(word);
uniqueAnagrams.push(word);
}
}
return combinedAnagrams;
};
console.log(findAnagrams(words));
@rmdhfz
Copy link
Author

rmdhfz commented Jan 10, 2022

child:

  • id
  • name
  • parent_id

parent:

  • id
  • name

Query SQL:
SELECT a.id, a.name, b.name as parent_name FROM child a LEFT JOIN parent b ON a.parent_id = b.id;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment