Skip to content

Instantly share code, notes, and snippets.

@lennym
Forked from EddieDev/jcci.js
Created November 18, 2011 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lennym/1378042 to your computer and use it in GitHub Desktop.
Save lennym/1378042 to your computer and use it in GitHub Desktop.
Javascript Code Challenge and Implementation. http://eblundell.com/javascript-challenge
Array.prototype.joinProperty = function(method, delim) {
var output = [];
for(var i=0; i < this.length; i++){
if(typeof this[i][method] == 'function'){
output.push(this[i][method]());
} else {
output.push(this[i][method]);
}
}
return output.join(delim);
}
x = {item:'coffee'}
y = {item:'milk'}
z = {item:'tea'}
var myArr = [x,y,z];
console.log(myArr.joinProperty('item'));
/**
* @constructor
*/
function testObject(message){
this.message = message;
}
testObject.prototype.getMessage = function() {
return this.message;
};
a = new testObject('paper');
b = new testObject('plastic');
c = new testObject('metal');
var secondArr = [a,b,c];
console.log(secondArr.joinProperty('getMessage', '-'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment