Skip to content

Instantly share code, notes, and snippets.

@jneira
Forked from joseanpg/phineas.js
Created August 13, 2011 20:22
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 jneira/1144214 to your computer and use it in GitHub Desktop.
Save jneira/1144214 to your computer and use it in GitHub Desktop.
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);
}
}
function phineas(a,sep) {
var acu = [];
aplaneitor(a,acu);
//Lo que sigue puede lograrse con un simple acu.join(sep)
//pero estoy evitando utilizar las funciones de Array.prototype
var text = acu[0].toString();
for (var j = 1, len= acu.length; j<len; j++) {
text += sep+acu[j];
}
return text;
}
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