Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created August 13, 2011 15:35
Show Gist options
  • Select an option

  • Save joseanpg/1143962 to your computer and use it in GitHub Desktop.

Select an option

Save joseanpg/1143962 to your computer and use it in GitHub Desktop.
var phineas = (function(){
function aplaneitor(soa,acu) {
if (soa instanceof Array) {
for (var j=0, len = soa.length;j<len;j++) {
aplaneitor(soa[j],acu);
}
}
else {
acu.push(soa);
}
}
return function(a,sep) {
var acu = [];
aplaneitor(a,acu);
return acu.join(sep);
}
})();
console.log(phineas(['a',['b',['c',['d']]]],'*'));
console.log(phineas(["hola", ["soy", ["juan", "fernandez"] ], "y", ["no", "tengo", ["dinero"] ] ],'+'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment