Skip to content

Instantly share code, notes, and snippets.

View bignimbus's full-sized avatar
🙃

Jeff Auriemma bignimbus

🙃
View GitHub Profile
@bignimbus
bignimbus / flattenAndAdd.js
Last active August 29, 2015 13:57
Given a JavaScript array, function flattens the array and returns the sum of all primitive-type numbers in the array. The function works recursively.
/*
Given a JavaScript array, function flattens the array and returns the sum of all primitive-type numbers in the array.
The function works recursively.
*/
function flattenAndAdd(arrayToFlatten) {
var originalArray = arrayToFlatten;
var repeat = 1;
@bignimbus
bignimbus / fibonacci.js
Last active April 19, 2022 21:42
projecteuler.net Problem 2: Fibonacci sum. A JavaScript solution.
/*
projecteuler.net
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
*/
@bignimbus
bignimbus / amicable.js
Last active May 14, 2021 16:09
projecteuler.net Problem 21: Amicable numbers. A JavaScript solution.
/*
projecteuler.net
Amicable numbers
Problem 21
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.
@bignimbus
bignimbus / removeDuplicates.js
Created March 25, 2014 12:15
I created a Google Sheet to organize short bursts of lesson plan content across grade and content levels at Dever School. Script automatically deletes out-of-date entries. Script will also sort the page after deleting duplicates so that up-to-date information appears first.
/*
I created a Google Sheet to organize short bursts of lesson plan content across grade and content levels at Dever School.
Script automatically deletes out-of-date entries.
Script will also sort the page after deleting duplicates so that up-to-date information appears first.
*/
function removeDuplicates(){
Logger.clear();
Logger.log("starting over...");
var ss = SpreadsheetApp.openById(**ID NUMBER HERE **); //get spreadsheet
@bignimbus
bignimbus / audio.json
Last active August 29, 2015 13:58
Initial impression of a standard json container for Web Audio API sound synthesis information portability.
{
"name" : "Fun Song",
"instruments" : {
"funSound" : {
"sources" : {
"1" : "sine",
"2" : "sine",
},
"envelope": {
"attack" : 0,
@bignimbus
bignimbus / applyAndCall.js
Last active August 29, 2015 14:01
A brief explanation of JavaScript's native .apply() and .call() functions.
// In a recent interview I was stumped by a question about JS's native
// function.apply() and function.call() methods. I resolved to learn more
// about why these methods are useful to a JS developer. Here's what I now
// understand:
// let's make a simple function that introduces an individual.
// We pass arguments defining the interests of the individual.
// The greeting is personalized by the value of this.name.
function introduceMe (interest1, interest2) {
var that = this;
@bignimbus
bignimbus / nameGenerator.js
Last active August 29, 2015 14:01
(unfinished) A random first name generator. Just for fun!
var
vowels = ['a', 'e', 'i', 'o', 'u', 'y'],
consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'],
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
function name (nameLength, numberOfNames) {
var names = [];
if (nameLength > 14) return 'too long!';
if (numberOfNames > 100 || numberOfNames < 0 || typeof numberOfNames !== 'number') numberOfNames = 1;
var
@bignimbus
bignimbus / rammstein.js
Last active August 29, 2015 14:07
Turns a normal array of words into German industrial metal lyrics.
Array.prototype.rammstein = function () {
var phrase = '', rammsteined = [];
this.forEach( function ( word ) {
phrase += word.toUpperCase() + ' ';
rammsteined.push( phrase );
});
return rammsteined;
}
@bignimbus
bignimbus / fakeMap.js
Last active August 29, 2015 14:08
Simple version of Array.prototype.map
Array.prototype.fakeMap = function (fn, context) {
var out = this instanceof Array ? [] : {},
context = context || this,
result,
n;
if (typeof fn !== "function") {
return [];
}
for (n in this) {
if (this.hasOwnProperty(n)) {
@bignimbus
bignimbus / math-pie.js
Last active October 16, 2015 20:03
Math.PIE() - a proposed ECMAScript 7 feature
// in order for this to work, you need a yummly dev account.
function makePie (response) {
var match = JSON.parse(response).matches[0],
yourPie = ["you could bake a delicious ",
match.recipeName,
" using "];
match.ingredients.forEach(function (ingredient) {
yourPie.push("[" + ingredient + "]");
});