This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name" : "Fun Song", | |
"instruments" : { | |
"funSound" : { | |
"sources" : { | |
"1" : "sine", | |
"2" : "sine", | |
}, | |
"envelope": { | |
"attack" : 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.rammstein = function () { | |
var phrase = '', rammsteined = []; | |
this.forEach( function ( word ) { | |
phrase += word.toUpperCase() + ' '; | |
rammsteined.push( phrase ); | |
}); | |
return rammsteined; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + "]"); | |
}); |
OlderNewer