Skip to content

Instantly share code, notes, and snippets.

View macikokoro's full-sized avatar

Joaquin Guardado macikokoro

View GitHub Profile
Running "simplemocha:all" (simplemocha) task
1..1
ok 1 Array indexOf() should return -1 when the value is not present
# tests 1
# pass 1
# fail 0
Done, without errors.
@macikokoro
macikokoro / funcArray.js
Created August 2, 2014 06:31
Accessing function expressions arrays.
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; }
];
alert( puzzlers[ puzzlers[1](3) ]( puzzlers[3](9) ) );
@macikokoro
macikokoro / poplarPuzzlers.js
Created August 2, 2014 05:56
Poplar Puzzlers codeschool
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;
@macikokoro
macikokoro / funcExpress.js
Created August 2, 2014 04:08
Example of calling a function expression with console.log.
function adventureSelector ( userChoice ) {
if (userChoice == 1) {
return function () {
alert("You've selected the Vines of Doom!\n" +
"Hope you have a swingin' time.");
};
} else if (userChoice == 2) {
return function () {
alert("Looks like you want the Lake of Despair!\n" +
"Watch out for crocs. And I ain't talkin' about shoes.");
@macikokoro
macikokoro / anotherMap.js
Created August 1, 2014 03:35
Another example of a function using the map method.
var modifiedNames = [ "Thomas Meeks",
"Gregg Pollack",
"Christine Wong",
"Dan McGaw" ];
modifiedNames.map(function(cell){ alert("Yo, " + cell + "!");});
//alerts Yo, name!
@macikokoro
macikokoro / mapFunc.js
Created August 1, 2014 03:00
Mapping a function to unite first and last names into one cell.
var passengers = [ ["Thomas", "Meeks"],
["Gregg", "Pollack"],
["Christine", "Wong"],
["Dan", "McGaw"] ];
var modifiedNames = passengers.map(function(cell){ return cell[0] + ' ' + cell[1];});
console.log(modifiedNames);
//This will log: ["Thomas Meeks", "Gregg Pollack", "Christine Wong", "Dan McGaw"]
@macikokoro
macikokoro / map.js
Created August 1, 2014 02:01
Arrays and map()
var numbers = [12, 4, 3, 9, 8, 6, 10, 1];
var results = numbers.map(function(arrayCell) {return arrayCell * 2;});
console.log(results);
@macikokoro
macikokoro / greeting.js
Created July 31, 2014 22:50
Function expressions
var greeting;
newCustomer = true;//change to false or true for diff result.
if(newCustomer){
greeting = function() {
alert("Thanks for visiting our site!\n" + "Discover our content!");
};
} else {
greeting = function() {
alert("Welcome back!\n" + "We have new content for you!");
@macikokoro
macikokoro / generator.js
Created July 25, 2014 08:56
Using a for loop to print out different states of a generator: off, on, power generated.
var totalGen = 19;
var totalMW = 0;
var totalGen = 19;
var totalMW = 0;
for (var gen = 1; gen <= totalGen; gen++) {
if (gen % 2 != 0) {
console.log("Generator #" + gen + " is off.");
@macikokoro
macikokoro / moreSheep.js
Created July 25, 2014 07:01
Loop to check for number divisible by 4 and reducing by 75%.
var numSheep = 4;
var monthsToPrint = 12;
for (var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++) {
if (monthNumber % 4 === 0) {
numSheep = numSheep / 4;
console.log("Removing " + numSheep * 3 + " sheep from the population. Phew!");
} else if (numSheep > 10000) {
numSheep = numSheep / 2;