Skip to content

Instantly share code, notes, and snippets.

View kenduigraha's full-sized avatar
🏠

Ken Duigraha Putra kenduigraha

🏠
View GitHub Profile
let solution = (record) => {
let answer = [];
let userChat = [];
for (let i = 0; i < record.length; i++) {
let command = record[i].split(" ")[0];
let userId = record[i].split(" ")[1];
let nickName = record[i].split(" ")[2];
let checkExistingUser = userChat
.map((data, index) => (data.userId === userId ? index : ""))
let solution = (n, users) => {
let answer = [];
let totalUsers = users.length;
let countDuplicateStageUsers = users.reduce((prev, curr) => {
prev[curr] = (prev[curr] || 0) + 1;
return prev;
}, {});
// looping stages
for (let i = 1; i <= n; i++) {
let solution = (relation) => {
let answer = 0;
let dataRow = [];
let findDuplicates = (arr) =>
arr.filter((item, index) => arr.indexOf(item) != index);
// - Uniqueness: The relation does not have two distinct tuples
// (i.e. rows or records in common database language)
// with the same values for these attributes.
for (let i = 0; i < relation[0].length; i++) {
// switchWordByIndex
// return new string switched by index
const switchWordByIndex = (words, index, wordSwitched) => (words.substr(0, index) + wordSwitched + words.substr(index + 1));
// swapWordBasedOnIndex
// return new string swaped
const swapStringBasedOnIndex = (words, indexWord, indexComparedWord) => {
// switch first word as temporary words
const switchFirstWord = switchWordByIndex(words, indexWord, words[indexComparedWord]);
// switch second word and get the result
// Given an array of random characters with size n,
// String[] stringArr = ["A", "C", "K", "B" .....];
// write a procedure that will scan the array from the first element
// and print the first character that appear three times during scanning
const TOTAL_APPEAR = 3;
function scanArray(data) {
let flag = 0;
const result = []
const dataLength = data.length;