Created
September 15, 2014 04:03
-
-
Save thedore17/995ee0be2e7fb4064977 to your computer and use it in GitHub Desktop.
Takes people objects and returns full names
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 Person = Class({ | |
initialize: function(first, last) { | |
this.firstName = first; | |
this.lastName = last; | |
}, | |
toString: function() { | |
return "My name is "+this.firstName+" "+this.lastName+" ."; | |
} | |
}); | |
var fullName = function(person_object) { | |
full_name = person_object.firstName + " " + person_object.lastName; | |
return full_name; | |
}; | |
var fullNameArray = function(person_array) { | |
name_array = []; | |
person_array.forEach(function(person) { | |
name = fullName(person); | |
name_array.push(name); | |
}); | |
return name_array; | |
}; | |
var kali = new Person('Kali', 'Kiger'); | |
console.log(kali.firstName); //displays "Kali" | |
console.log(kali.lastName); //displays "Kiger" | |
console.log(kali.toString()); //displays "My name is Kali Kiger" | |
console.log(fullName(kali)); // displays "Kali Kiger" | |
var ted = new Person('Theodore', 'Henderson'); | |
var people = [kali, ted]; | |
console.log(fullNameArray(people)); // returns ['Kali Kiger', 'Theodore Henderson'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment