Last active
September 26, 2023 07:15
-
-
Save ameunoia/70abcb7f7662c50dde513b6196a300ed to your computer and use it in GitHub Desktop.
Pre Assessment Software Engineer - Back End Ultra Voucher
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
-- create | |
CREATE TABLE family ( | |
id INTEGER PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
parent_id INTEGER | |
); | |
-- insert | |
INSERT INTO family values (1, 'Zaki', 2); | |
INSERT INTO family values (2, 'Ilham', null); | |
INSERT INTO family values (3, 'Irwan', 2); | |
INSERT INTO family values (4, 'Arka', 3); | |
-- select | |
SELECT f.id, f.name, fj.name AS parent_name FROM family AS f | |
LEFT JOIN family AS fj ON fj.id = f.parent_id; |
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
const array = ["cook", "save", "taste", "aves", "vase", "state", "map"]; | |
console.log(grouping(array)); | |
function grouping(datas) { | |
const groups = []; | |
for (let i = 0; i < datas.length; i++) { | |
let grouped = false; | |
for (let j = 0; j < groups.length; j++) { | |
if (isAnagram(groups[j][0], datas[i])) { | |
groups[j].push(datas[i]); | |
grouped = true; | |
break; | |
} | |
} | |
if (!grouped) { | |
groups.push([datas[i]]); | |
} | |
} | |
return groups; | |
} | |
function isAnagram(name1, name2) { | |
if (name1.length !== name2.length) { | |
return false; | |
} | |
return sortingString(name1) === sortingString(name2); | |
} | |
function sortingString(string) { | |
let char = []; | |
let sorting; | |
let result = ""; | |
//make string to array of character | |
for (let i = 0; i < string.length; i++) { | |
char.push(string[i]); | |
} | |
//sortir array of char with bubble sort | |
// char.sort(); | |
do { | |
sorting = false; | |
for (let i = 0; i < char.length; i++) { | |
if (char[i] > char[i + 1]) { | |
const temp = char[i]; | |
char[i] = char[i + 1]; | |
char[i + 1] = temp; | |
sorting = true; | |
} | |
} | |
} while (sorting); | |
//if sortir done, then convert array to string | |
// char = char.join(""); | |
for (let i = 0; i < char.length; i++) { | |
result += char[i]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment