Skip to content

Instantly share code, notes, and snippets.

@wchiquito
Created August 13, 2011 23:27
Show Gist options
  • Select an option

  • Save wchiquito/1144366 to your computer and use it in GitHub Desktop.

Select an option

Save wchiquito/1144366 to your computer and use it in GitHub Desktop.
v.2/Ejercicio 1/Reunión #3/Grupo de Estudio JavaScript
/*
.isArray
Implemented in: JavaScript 1.8.5
ECMAScript Edition: ECMAScript 5th Edition
MDN Docs http://goo.gl/AjneU
*/
/* From MDN Docs http://goo.gl/AjneU */
if(!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
};
}
function arrayConcatenator(input) {
var maxlen,
index,
current,
stringResult = [];
if (Array.isArray(input)) {
maxlen = input.length;
for (index = maxlen; index > 0; index--) {
current = input[maxlen - index];
if (Array.isArray(current)) {
current = arrayConcatenator(current);
}
stringResult.push(current);
}
}
return stringResult.join();
}
console.group("strings y vectores anidados")
console.assert(
"hola,soy,juan,fernandez,y,no,tengo,dinero"
===
arrayConcatenator(["hola",["soy",["juan","fernandez"]],"y",["no","tengo",["dinero"]]]),
"retorna 'hola,soy,juan,fernandez,y,no,tengo,dinero'");
console.groupEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment