Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠

Ken Duigraha Putra kenduigraha

🏠
View GitHub Profile
View group anagram
// 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
View solution number 3
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++) {
View solution number 2
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++) {
View solution number 1
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 : ""))
@kenduigraha
kenduigraha / cloudSettings
Created Jan 22, 2019
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2019-01-22T04:16:46.206Z","extensionVersion":"v3.2.4"}
View Fraction for Rupiah
const fractions = [100000, 50000, 20000, 10000, 5000, 1000, 500, 100, 50];
var result = [];
var noFractionValue;
function doCheckNoFraction(input) {
return input < fractions[fractions.length-1]
}
function doCalculate(input) {
View gist:42c4189f1f8e945c3389eac1c09f5050
var result = [];
var count = 0;
var resultCount = [];
function decimalToBinary(decimal) {
var divide = decimal / 2;
var divideRound = Math.floor(divide);
decimal % 2 != 0 ? result.push(1) : result.push(0);
View longest binary gap
var result = [];
var count = 0;
var resultCount = [];
function longestBinaryGap(decimal) {
var divide = decimal / 2;
var divideRound = Math.floor(divide);
if (decimal % 2 != 0) {
count = 0;
View test.js
webpackJsonp([1,2],{109:function(e,t,a){"use strict";function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1];for(var a in t)void 0===e[a]&&(e[a]=t[a]);return e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default},115:function(e,t,a){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var
View recursive fibonacci
function fibonacci(n){
if(n === 1){
return [0]
}else{
var s = fibonacci(n-1)
s.push(s[s.length - 1] + ((s.length === 1) ? 1 : s[s.length - 2]))
return s;
}
}
// 0 1 1 2 3 5 8 13 21 34