Created
September 26, 2023 10:15
-
-
Save ReadTheFuckingManual/fcddcab11b83b6673ffc494b88211f4c to your computer and use it in GitHub Desktop.
Revisions
-
EkoEdyPurwanto created this gist
Sep 26, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ module EkoEdyPurwanto/BackEnd-UltraVoucher go 1.21.1 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ package main import ( "fmt" ) func sortString(s string) string { chars := []rune(s) n := len(chars) for i := 0; i < n-1; i++ { for j := i + 1; j < n; j++ { if chars[i] > chars[j] { chars[i], chars[j] = chars[j], chars[i] } } } return string(chars) } func groupAnagrams(words []string) [][]string { anagramGroups := make(map[string][]string) for _, word := range words { sortedWord := sortString(word) anagramGroups[sortedWord] = append(anagramGroups[sortedWord], word) } var result [][]string for _, group := range anagramGroups { result = append(result, group) } return result } func main() { words := []string{"cook", "save", "taste", "aves", "vase", "state", "map"} anagramGroups := groupAnagrams(words) fmt.Println(anagramGroups) } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ -- STEP-STEP YANG SAYA LAKUKAN UNTUK MENYELESAIKAN QUERY TEST -- pertama saya akan membuat database dan saya namai query_test CREATE DATABASE query_test OWNER ekoedyp; -- kedua saya akan membuat table dan saya namai people CREATE TABLE people ( id INT PRIMARY KEY, name VARCHAR(255), parent_id INT ); -- ketiga saya akan mengisi table people sesuai dengan assesment INSERT INTO people (id, name, parent_id) VALUES (1, 'Zaki', 2), (2, 'Ilham', NULL), (3, 'Irwan', 2), (4, 'Arka', 3); -- keempat saya akan mengecek hasil isian dari step ketiga SELECT * FROM people; -- kelima saya akan membuat Query SELECT JOIN untuk menghasilkan data yang sesuai dengan assesment result SELECT p1.id, p1.name, p2.name AS parent_name FROM people p1 LEFT JOIN people p2 ON p1.parent_id = p2.id;