Skip to content

Instantly share code, notes, and snippets.

View SeeThruHead's full-sized avatar

Shane Keulen SeeThruHead

View GitHub Profile
console.log(
Array.apply(null, {length: 100}).map(function(val, index) {
return (++index%3?'':'Fizz')+(index%5?'':'Buzz')||index;
}).join('\n')
);
console.log(
Array.apply(null, {length: 100}).map(function(val, index) {
index++;
if (index % 15 == 0){return "FizzBuzz";}
@SeeThruHead
SeeThruHead / fillArray.js
Created December 20, 2014 20:44
Fill an array with another array, repeating when necessary.
// Init a source array contains numbers 0-35
var source = Array.apply(null, {length: 36}).map(Number.call, Number);
// Init the result array as undefined using the arguments pseudo array.
var result = Array.apply(null, {length: 100});
// The magic
result = result.map(function(val, index) {
return source[index % source.length];
});
@SeeThruHead
SeeThruHead / checkInputSum
Created December 8, 2014 05:42
Throw error if a group of inputs is over a certain sum
function checkSum(groupOfInputs, maxValue) {
groupOfInputs = $(groupOfInputs);
groupOfInputs.on('change keyup paste', function() {
$this = $(this);
var values = groupOfInputs.map(function() {return $(this).val();}).get();
var sum = values.reduce(function(one, two) {
return Number(one) + Number(two);
});
if (sum > maxValue) {
alert('Too big!');