Skip to content

Instantly share code, notes, and snippets.

@electricjesus
Created November 5, 2014 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electricjesus/736e5cd7a3614de9c6d6 to your computer and use it in GitHub Desktop.
Save electricjesus/736e5cd7a3614de9c6d6 to your computer and use it in GitHub Desktop.
// Level 1 mission
// The code does not execute properly. Try to figure out why.
function multiply(a, b){
a * b
}
// Level 2 mission
//2. Correct this code, so that the greet function returns the expected value.
function Person(name){
this.name = name;
}
Person.prototype.greet = function(otherName){
return "Hi " + otherName + ", my name is " + name;
}
//3. create a function to find the last element of a list:
/* use cases:
last( [1,2,3,4] ) # => 4 Level 3 Achievement
last( "xyz" ) # => z Level 4 Achievement
last( 1,2,3,4 ) # => 4 Level 5 Achievement
bonus: doesn't have an explicit argument Level 5B Achievement
example:
*/
last = function() {
// do your thing here
}
/*
Level 6 & 7:
Description:
Write a function that will take an array and a person object as parameters. The function will only push a "person" object onto the end of an array if someone with that phone number doesn't already exist in that array.
-A "person" is a javascript object with a name and a phoneNumber : {name:'SomeName', phoneNumber:1234567890}
-A duplicate person object is an object with the same phoneNumber as someone else
If the person object is unique, push them onto the end of the array, and return true.
If the person object is NOT unique, don't push them to the array and return false;
If the person doesn't have a phoneNumber, don't add them to the array and return false.
Level 7 is achieved if reference is returned automatically, and/or if using the prototype structure. See below:
example structure(s):
*/
uniquePush = function(array, item) {
// do your thing here
}
/* WHERE example usage is:
var alphabet = ['a','b','c'];
uniquePush(alphabet,'d'); // alphabet is now ['a','b','c','d']
uniquePush(alphabet,'c'); // alphabet remains ['a','b','c','d']
// OR
*/
Array.prototype.uniquePush = function() {
// do your thing here
}
/* WHERE example usage is:
var alphabet = ['a','b','c'];
alphabet.uniquePush('d'); // alphabet is now ['a','b','c','d']
alphabet.uniquePush('c'); //alphabet remains ['a','b','c','d']
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment