Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solucion al ejercicio Concatenator #gejs
var example=["hola",3,["soy",function(){}, ["juan", "fernandez"] ], "y",new Date(), ["no", "tengo",function(){},["dinero",[]] ] ];
/* Using .isArray ECMAS5
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray */
if(!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
var concatena=function(obj,character){
character = character || ',';
var result='',partialResult,concatenator;
if(typeof(obj)=='string'){
return obj;
}
if (Array.isArray(obj)){
for(var i=0,z=obj.length;i<z;i++){
partialResult=concatena(obj[i],character);
concatenator = i>0 ? character : '';
if(partialResult!=''){
result += concatenator+partialResult;
}
}
}
return result;
}
concatena(example,'-');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.