Last active
March 27, 2017 01:51
-
-
Save edutrul/43a39bf05b7e975d81f544225a2697c8 to your computer and use it in GitHub Desktop.
JAVASCRIPT self study - EDUTRUL
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
var passengers = [ | |
["Thomas", "Meeks"], | |
["Gregg", "Pollack"], | |
["Christine", "Wong"], | |
["Dan", "McGaw"] | |
]; | |
var modifiedNames = passengers.map(function (arrayCell) { | |
return arrayCell[0] + ' ' + arrayCell[1]; | |
}); | |
console.log(modifiedNames); | |
// OUtput: ["Thomas Meeks", "Gregg Pollack", "Christine Wong", "Dan McGaw"] |
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 warningMaker(obstacle) { | |
var count = 0; | |
var zones = []; | |
return function(number, location) { | |
count++; | |
var list = ""; | |
// add each location to the zones array | |
zones.push(location); | |
// add each zone to the list string | |
list = zones.join("\n"); | |
alert("Beware! There have been " + obstacle + | |
" sightings in the Cove today!\n" + | |
number + " have been spotted at the " + | |
location + "!\n" + | |
"This is alert #" + count + | |
" today for " + obstacle + " danger.\n" + "CUrrent danger zones are:" + "\n" + list); | |
}; | |
} | |
print = warningMaker("hey"); | |
print(3, "Peru"); | |
print(5, "Arg"); |
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
var puzzlers = [ | |
function(a) { return 8 * a - 10; }, | |
function(a) { return (a - 3) * (a - 3) * (a - 3); }, | |
function(a) { return a * a + 4; }, | |
function(a) { return a % 5; } | |
]; | |
var start = 2; | |
var applyAndEmpty = function(input, queue) { | |
var length = queue.length; | |
for (var i = 0; i < length; i++) { | |
input = queue.shift()(input); | |
} | |
return input; | |
}; | |
alert(applyAndEmpty(start, puzzlers)); |
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 adventureSelector(userChoice) { | |
// return anonymous functions inside conditional blocks | |
switch (userChoice) { | |
case 1: | |
return function () { alert("You selected the Vines of Doom!"); }; | |
case 2: | |
return function () { alert("You selected the Vines of Doom!"); }; | |
case 3: | |
return function () { alert("The Caves of Catastrophe!"); }; | |
} | |
} | |
adventureSelector(1)(); | |
// Outputs: You selected the Vines of Doom! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment