Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am daubattu on github.
  • I am daubattu (https://keybase.io/daubattu) on keybase.
  • I have a public key ASBTpgg7GynCVrzIEtnznswkwvUA31GHj-Om_4ZCGZatrwo

To claim this, I am signing this object:

@daubattu
daubattu / hackerrank_solution_of_between_two_sets_in_javascript.js
Created October 21, 2019 09:46
[Hackerrank] Solution of Between Two Sets in JavaScript
function getTotalX(a, b) {
// Write your code here
let result = 0;
let index = 1;
let cloneA = a.splice(1, a.length); // clone new array of a but not a[0]
while(a[0] * index <= b[0]) {
if(
cloneA.every(item => (a[0] * index) % item === 0)
&&
b.every(item => item % (a[0] * index) === 0)
@daubattu
daubattu / hackerrank_solution_of_breaking_the_records_in_javascript.js
Created October 22, 2019 10:45
[Hackerrank] Solutions of Breaking the Records in JavaScript
function breakingRecords(scores) {
let best = 0;
let worst = 0;
let bestScore = scores[0];
let worstScore = scores[0];
const lengthOfData = scores.length;
for(let i = 1; i < scores.length; i++) {
if (scores[i] > bestScore) {
bestScore = scores[i];
best++;
@daubattu
daubattu / hackerrank_solution_of_birthday_chocolate_in_javascript.js
Created October 22, 2019 13:29
[Hackerrank] Solution of Birthday Chocolate in JavaScript
function birthday(s, d, m) {
let result = 0;
for(let i = 0; i < s.length - (m - 1); i++) {
if (s.slice(i, i + m).reduce((r, v) => r + v, 0) === d) {
result++;
}
}
return result;
}
@daubattu
daubattu / hackerrank_solution_of_divisible_sum_pairs_in_javascript.js
Created October 22, 2019 14:01
[Hackerrank] Solution of Divisible Sum Pairs in JavaScript
function divisibleSumPairs(n, k, ar) {
let result = 0;
for(let i = 0; i < n - 1; i++) {
result += ar.slice(i + 1, n).filter((item, index) => {
if ((item + ar[i]) % k === 0) {
return item;
}
}).length;
}
return result;
@daubattu
daubattu / hackerrank_solution_of_bon_appétit_in_javascript.js
Created October 26, 2019 06:19
[Hackerrank] Solution of Bon Appétit in JavaScript
function bonAppetit(bill, k, b) {
const sum = bill.reduce((r, v) => r + v, 0);
const result = (sum - bill[k])/2;
if (b - result === 0) console.log('Bon Appetit');
else console.log(b - result);
}
@daubattu
daubattu / hackerrank_solution_of_drawing_book_sets_in_javascript.js
Created October 28, 2019 09:59
[Hackerrank] Solution of Drawing Book in JavaScript
function pageCount(n, p) {
/*
* Write your code here.
*/
const pageFromStart = Math.floor(p/2);
const pageFromEnd = Math.ceil(((n % 2 !== 0 ? n - 1 : n) - p)/2);
return Math.min(pageFromStart, pageFromEnd);
}
@daubattu
daubattu / hackerrank_solution_of_electronics_shop_in_javascript.js
Created October 29, 2019 15:08
[Hackerrank] Solution of Electronics Shop in JavaScript
function getMoneySpent(keyboards, drives, b) {
/*
* Write your code here.
*/
let max = -1;
for(let i = 0; i < keyboards.length; i++) {
const keyboardPrice = keyboards[i];
for(let j = 0; j < drives.length; j++) {
const drivePrice = drives[j];
const users = [
{
id: 1,
name: 'Nguyễn Hưng Khánh',
girl_friend: {
name: 'Nguyễn Thị Khánh',
address: 'Hà Nội'
}
},
{
// users[0]
console.log(users[0].girl_friend.name)
// users[1]
if (users[1].girl_friend) {
console.log(users[1].girl_friend.name)
} else {
console.log('Lêu lêu. Thằng này ê sắc ế')
}