Skip to content

Instantly share code, notes, and snippets.

@keeganbrown
Last active November 21, 2015 17:13
Show Gist options
  • Save keeganbrown/101aff0ba9a7930fcad6 to your computer and use it in GitHub Desktop.
Save keeganbrown/101aff0ba9a7930fcad6 to your computer and use it in GitHub Desktop.
Stuff I did hanging out at smashing boxes
"use strict";
function findMult ( limit ) {
let mulOfX = ( num, x ) => { return !(num % x) }
let multiples = [];
while ( --limit ) {
if ( mulOfX(limit, 5) || mulOfX( limit, 3 ) ) {
multiples.push( limit );
}
}
return multiples.reduce( (prev, next) => {
return prev+next;
}, 0);
}
console.log( findMult(1000) );
"use strict";
function findMult ( limit ) {
let mulOfX = ( num, x ) => { return !(num % x) }
let multiples = [];
while ( --limit ) {
if ( mulOfX(limit, 5) ) {
multiples.push( limit );
} else if ( mulOfX( limit, 3 ) ) {
multiples.push( limit );
}
}
return multiples.reduce( (prev, next) => {
return prev+next;
}, 0);
}
console.log( findMult(1000) );
"use strict";
//Was sad about the incompleteness of the pair programming attempt with Brandon,
//so figured I'd hash this out all the way here.
function convertToRoman ( decimal ) {
if ( !decimal ) decimal = 354; //for easy testing
let forEachInHash = ( hash, cb ) => {
for ( let key in hash ) {
cb( hash[key], key );
}
}
let buildarr = ( num, str ) => {
let arr = [];
while ( --num >= 0) {
arr.push(str);
}
return arr;
}
let _decimal = decimal;
let romanStrArr = [];
[ { roman: 'C', decimal: 100 },
{ roman: 'L', decimal: 50 },
{ roman: 'X', decimal: 10 },
{ roman: 'V', decimal: 5 },
{ roman: 'I', decimal: 1 }
].forEach( (map, key) => {
let _num = Math.floor( _decimal/map.decimal );
_decimal -= _num*map.decimal;
romanStrArr = romanStrArr.concat( buildarr( _num, map.roman ) );
});
return romanStrArr.join('');
}
console.log( convertToRoman( parseInt(process.argv[2])) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment