Skip to content

Instantly share code, notes, and snippets.

@rodriguezmanu
rodriguezmanu / maxLenghtItemAndOccurs.js
Created October 8, 2018 22:33
maxLenghtItemAndOccurs
function test(arr) {
let max = 0;
let result = '';
const obj = {};
let maxO = 0;
let maxAnimal = '';
arr.forEach(item => {
const a = item.split('');
if (a.length > max) {
@rodriguezmanu
rodriguezmanu / numberOfWaysToPay.js
Created October 8, 2018 22:26
numberOfWaysToPay
function numberOfWaysToPay(denominations, denominationCount, rent) {
const ways = [];
for (let i = 0; i <= rent; i++) {
ways.push(0);
}
ways[0] += 1;
for (let j = 0; j < denominations; j++) {
const coin = denominationCount[j];
@rodriguezmanu
rodriguezmanu / solution.js
Created February 8, 2018 02:44
Degree of an Array
function solution(data) {
let degree = 1;
let degreePos = data[0];
const map = new Map();
for (let i = 0; i < data.length; i++) {
const element = data[i];
if (map.has(element)) {
const pos = map.get(element);
@rodriguezmanu
rodriguezmanu / solution.js
Last active February 8, 2018 02:42
Counter occurrences digits
function count_digits(d, n) {
let count = 0;
for (let index = 0; index <= n; index++) {
const a = index.toString();
if (d == a) {
count++;
}
if (a.length > 1) {
@rodriguezmanu
rodriguezmanu / solution.js
Last active March 5, 2018 00:07
nextMessage
var path = require('path')
var funcs = require('./funcs')
var session = {
username: process.argv[2],
lastMessageHash: process.argv[3]
}
if (!session.username || !session.lastMessageHash) {
console.log('Usage: node index.js <username> <hash>')
@rodriguezmanu
rodriguezmanu / parse.js
Created January 16, 2018 23:59
parse elements html
(function() {
'use strict';
function parseHTMLMenu(fs) {
let html = '<ul>';
for (let key in fs) {
const element = fs[key];
html += '<li>';
if (Array.isArray(element.sub)) {
html += element.txt;
html += parseHTMLMenu(element.sub);
function parseElement(element) {
if (element.length === 1) {
return `</${element[0]}>`;
}
if (Array.isArray(element)) {
let tag = element.shift();
let toReturn = `<${tag}>`;
toReturn = element.reduce((result, el) => {
if (el) {
function averageColors(color1, color2) {
const c1 = splitColor(color1),
c2 = splitColor(color2),
res = [];
let index = 0;
while (index !== c1.length) {
res.push(average(c1[index], c2[index]));
index++;
@rodriguezmanu
rodriguezmanu / flatten.js
Last active July 15, 2016 16:05
Flatten Arrays
(function() {
'use strict';
function flattenES6(arr) {
return arr.reduce(function (flatten, toFlatten) {
return flatten.concat(Array.isArray(toFlatten) ? flattenES6(toFlatten) : toFlatten);
}, []);
}
function flattenES5(arr) {