Array functions
//////////////////////////////////////////////////////////////////////////////
// FILE : arr.js
// AUTHOR : http://www.asolver.com
// PURPOSE : Array functions
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
var ArrNil = new Array(); // The empty array
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function Arr2Txt(arr, // Array
sep, // Separator (optional)
ini, // Initial text (optional)
end, // Final text (optional)
lsp) // Last separator (optional)
// PURPOSE: Returns a text with the catenation of all element in the array.
// The last separator lets do list like 1, 2, 3 y 4.
//////////////////////////////////////////////////////////////////////////////
{
if(!sep) { sep = ""; } // If not definned then the empty string
if(!ini) { ini = ""; } // If not definned then the empty string
if(!end) { end = ""; } // If not definned then the empty string
if(!lsp) { lsp = sep; } // If not definned then like the separators
var str = ini;
for(var pos=0; pos < arr.length; pos++)
{
if(pos==0) { str = str + arr[pos]; } // The first
else if((pos+1)==arr.length) { str = str + lsp + arr[pos]; } // The last
else { str = str + sep + arr[pos]; } // Middle
}
return(str+end);
}
//////////////////////////////////////////////////////////////////////////////
function Arr2Pag(arr, // Array of numbers of pages
end) // Ending (optional, default ".")
// PURPOSE: Returns a text with the catenation of all pages in the array,
// ordered and unique.
//////////////////////////////////////////////////////////////////////////////
{
var ini = "página"; // Init for one
if(!end) { end = "."; }
var uni = ArrStrUni(arr); // Order and remove duplicates pages
if(uni.length < 1) { ini = "adicional"; } // For 0
else if(uni.length > 1) { ini = ini+"s"; } // For 2, 3, ...
var res = Arr2Txt(uni, ", ", ini+" ", end, " y "); // Pages
return(res);
}
//////////////////////////////////////////////////////////////////////////////
function Arr2Ul(arr, // Array of numbers of pages
cla) // Optional
// PURPOSE: Returns a basic html ul/li list.
//////////////////////////////////////////////////////////////////////////////
{
if(cla && cla!="") { cla = " class='"+cla+"'"; }
var res = Arr2Txt(arr, // Array
"</li><li"+cla+">", // Separator
"<ul><li" +cla+">", // Initial
"</li></ul>"); // End
return(res);
}
SHi.SyntaxHighlight funciones de sintaxis realzada de codigo
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio