Created
April 13, 2023 09:18
-
-
Save rizkyputri13/37115debbd90a0e19d055b216118ee6c to your computer and use it in GitHub Desktop.
This file contains 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
No. 1 | |
// Terdapat sebuah array of strings sebagai berikut: | |
// ['cook', 'save', 'taste', 'aves', 'vase', 'state', 'map'] | |
// Buatlah sebuah fungsi yang mengelompokkan sebuah array of strings di atas menjadi kumpulan anagram, dengan expected result sebagai berikut: | |
// [ | |
// [ 'cook' ], | |
// [ 'save', 'aves', 'vase' ], | |
// [ 'taste', 'state' ], | |
// [ 'map' ] | |
// ] | |
function groupAnagrams(words) { | |
let anagram = {}; | |
for (let word of words) { | |
let sortedWord = word.split("").sort().join(""); | |
if (!anagram[sortedWord]) { | |
anagram[sortedWord] = [word]; | |
} else { | |
anagram[sortedWord].push(word); | |
} | |
} | |
return Object.values(anagram); | |
} | |
let words = ["cook", "save", "taste", "aves", "vase", "state", "map"]; | |
console.log(groupAnagrams(words)); | |
No. 2 | |
//Buatlah query SQL : | |
SELECT t1.id, t1.name, t2.name AS parent_name | |
FROM EMPLOYEE t1 | |
LEFT JOIN EMPLOYEE t2 ON t1.parent_id = t2.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment