Last active
August 29, 2015 14:28
-
-
Save rpearce/d99914a0e258d3d7de5e to your computer and use it in GitHub Desktop.
Teaching Functions
This file contains 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
function greet(name, day, special) { | |
// your code here | |
} | |
greet('Robert', 'Tuesday', 'fried catfish'); // This should return the String "Hello, Robert. Today is Tuesday, and the special is fried catfish." | |
// ========================================================== | |
function sumOf(numbers) { | |
// your code here | |
} | |
sumOf([27, 312, 91]); // This should return the sum of the numbers passed via the array | |
// ========================================================== | |
function averageOf(numbers) { | |
// your code here | |
} | |
averageOf([1, 2]); // This should return the average of the numbers passed via the array. | |
// ========================================================== | |
function calculateStatistics(scores) { | |
// your code here | |
} | |
var statistics = calculateStatistics([5, 3, 100, 3, 9]); // This should return an object with keys `min`, `max` and `sum` | |
statistics.min // => 3 | |
statistics.max // => 100 | |
statistics.sum // => 120 | |
// ========================================================== | |
var songs = [ | |
{ | |
id: 1, | |
title: "Mother", | |
author: "Pink Floyd", | |
album: "The Wall" | |
}, | |
{ | |
id: 2, | |
title: "Since I've been Loving You", | |
author: "Led Zeppelin", | |
album: "Led Zeppelin III" | |
}, | |
{ | |
id: 3, | |
title: "Re: Stacks", | |
author: "Bon Iver", | |
album: "For Emma, Forever Ago" | |
}, | |
{ | |
id: 4, | |
title: "Von", | |
author: "Sigur Rós", | |
album: "Hvarf-Heim" | |
} | |
]; | |
var idsAndTitles = []; | |
// Use forEach to create objects containing only `id` and `title` for each song. | |
// Place each of these objects into the `idsAndTitles` array using Array's push() method. | |
// This should return something like [{ id: 1, title: "Foo" }, { id: 2, title: "Bar" }] | |
// your code here | |
// ========================================================== | |
Array.prototype.mapIt = function(callback) { | |
var results = []; | |
this.forEach(function(itemInArray) { | |
// your code here | |
}); | |
return results; | |
}; | |
songs.mapIt(function(song) { | |
return { id: song.id, title: song.title }; | |
}); // Should return something like [{ id: 1, title: "Foo" }, { id: 2, title: "Bar" }] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment