Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View amejiarosario's full-sized avatar
🎯
Think big, start small, learn fast!

Adrian Mejia amejiarosario

🎯
Think big, start small, learn fast!
View GitHub Profile
/**
* Sort array in asc order using merge-sort
* @example
* sort([3, 2, 1]) => [1, 2, 3]
* sort([3]) => [3]
* sort([3, 2]) => [2, 3]
* @param {array} array
*/
function sort(array = []) {
const size = array.length;
function indexOf(array, element, offset = 0) {
// split array in half
const half = parseInt(array.length / 2);
const current = array[half];
if(current === element) {
return offset + half;
} else if(element > current) {
const right = array.slice(half);
return indexOf(right, element, offset + half);
function findXYZ(n) {
const solutions = [];
for(let x = 0; x < n; x++) {
for(let y = 0; y < n; y++) {
for(let z = 0; z < n; z++) {
if( 3*x + 9*y + 8*z === 79 ) {
solutions.push({x, y, z});
}
}
function sort(n) {
for (let outer = 0; outer < n.length; outer++) {
let outerElement = n[outer];
for (let inner = outer + 1; inner < n.length; inner++) {
let innerElement = n[inner];
if(outerElement > innerElement) {
// swap
n[outer] = innerElement;
function hasDuplicates(n) {
const duplicates = [];
for (let outter = 0; outter < n.length; outter++) {
for (let inner = 0; inner < n.length; inner++) {
if(outter === inner) continue;
if(n[outter] === n[inner]) {
return true;
}
function findMax(n) {
let max;
let counter = 0;
for (let i = 0; i < n.length; i++) {
counter++;
if(max === undefined || max < n[i]) {
max = n[i];
}
}
return max;
const dictionary = {the: 22038615, be: 12545825, and: 10741073, of: 10343885, a: 10144200, in: 6996437, to: 6332195 /* ... */};
function getWordFrequency(dictionary, word) {
return dictionary[word];
}
console.log(getWordFrequency(dictionary, 'the'));
console.log(getWordFrequency(dictionary, 'in'));
function isEvenOrOdd(n) {
return n % 2 ? 'Odd' : 'Even';
}
console.log(isEvenOrOdd(10)); // => Even
console.log(isEvenOrOdd(10001)); // => Odd
version: '3.7'
services:
# http://localhost:8187/
nginx:
# build: .
image: nginx
# container_name: nginx
ports:
- "8187:80"
networks:
# https://github.com/elastic/stack-docker/blob/06db66617b7c6935df097b59c94a6085bad3de6a/docker-compose.yml
version: '3.6'
services:
# http://localhost:8187/
nginx:
# build: .
image: nginx
# container_name: nginx
ports: