Skip to content

Instantly share code, notes, and snippets.

View nimamehanian's full-sized avatar
🎧
Focused

Nima Mehanian nimamehanian

🎧
Focused
View GitHub Profile
@nimamehanian
nimamehanian / splort.js
Last active September 6, 2015 01:18
Toy problem: SplitSort. Given an input string, render the space-separated entries across `n` columns, vertically, and in alphabetical order. (i.e., implement an elementary UNIX `ls -a` command)
// test strings
var str1 = 'the quick brown fox jumps over the lazy dog and this is probably the longest sentence you have ever come across because it just has so many words in it that it just runs on and on needlessly can you tell';
var str2 = 'Oh, what a harmony of abandonment and impulse, of unnatural and yet graceful postures, in that mystical language of limbs, freed from the weight of corporeal matter, marked quantity infused with new substantial form, as if the holy band were struck by an impetuous wind, breath of life, frenzy of delight, rejoicing song of praise miraculously transformed, from the sound that it was, into image.';
var rand = 'Oh, what a harmony of abandonment? and impulse!, of unnatural (and yet graceful) postures, in that mystical language of limbs, freed from the weight of corporeal matter, marked quantity infused with new substantial form; as if the holy band were struck by an impetuous wind, breath of life: frenzy of delight: rejoicing song of praise, miraculously transformed, fro

Keybase proof

I hereby claim:

  • I am nimamehanian on github.
  • I am nimamehanian (https://keybase.io/nimamehanian) on keybase.
  • I have a public key ASAJNQGxsMuKcxAzb0zoKZOkmklWfLI0xa4C7SND8G1d4go

To claim this, I am signing this object:

const flattenDeep = array => (
array && array.constructor.name === 'Array' ?
array.toString().split(',').map(num => +num) : []
);
@nimamehanian
nimamehanian / poisonPlants.js
Created February 13, 2018 09:07
Hacker Rank Problem
const data = [6, 5, 8, 4, 7, 10, 9];
const daysTillPlantDeath = (toxicities, daysElapsed) => {
const livingPlants = toxicities.filter((poisonLevel, idx) => (
idx === 0 || (idx > 0 && poisonLevel <= toxicities[idx - 1])
));
return livingPlants.join('') === toxicities.join('') ?
daysElapsed : daysTillPlantDeath(livingPlants, daysElapsed + 1);
};
@nimamehanian
nimamehanian / makeChange.js
Created February 13, 2018 09:53
Change-making problem
const makeChange = (tier, divisors) => {
if (!tier.length) { return false; }
const nextTier = tier.reduce((t, n) =>
[...t, ...divisors.map(div => n - div)], []
).filter(val => val > -1);
return nextTier.indexOf(0) === -1 ?
makeChange(nextTier, divisors) : true;
};
makeChange([10], [3, 4]);
@nimamehanian
nimamehanian / conway.js
Created August 11, 2020 23:25
Conway Game Of Life
const gen0 = [
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];
// CONWAY GAME OF LIFE — CONSTRAINTS:
// Any live cell with 0 or 1 live neighbors dies by underpopulation.
// Any live cell with 2 or 3 live neighbors stays alive.