Nombre de lignes : 63 lignes
Afficher ce fichier en plein écran
- <html>
- <head>
- <title>Implémentation types</title>
- <script type="text/javascript" src="Array_update.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- var a=["DUPONT","PERRET","DASILVA","DURANT","DESMARTIN"];
- document.write("<table border=1><tr>");
- for(i=0;i<a.length;i++){
- document.write("<td>"+a[i]+"</td>");
- }
- document.write("</tr></table>");
- //1 first()
- document.write("première occurence =>"+a.first());
- //2 last()
- document.write("<br/>Dérnière occurence => "+a.last());
- //3 hasValue(v)
- document.write("<br/>le tableau possède le nom DA SYLVA=>");
- document.write((a.hasValue("DA SYLVA"))?"OUI":"NON");
- document.write("<br/>le tableau possède le nom DASILVA=>");
- document.write((a.hasValue("DASILVA"))?"OUI":"NON");
- //4 each
- /*
- * j'utilise la le paramètre index pour obtenir l'index de l'occurence
- */
- a.each(function(index){
- var newName="";
- this[index]=this[index].toLowerCase();
- });
- document.write("<table border=1><tr>");
- for(i=0;i<a.length;i++){
- document.write("<td>"+a[i]+"</td>");
- }
- document.write("</tr></table>");
- //5 interset(array)
- var t=["dupont","perret","paul","dubonnet","dasylva"];
- var f=a.intersect(t);
- document.write("<table border=1><tr>");
- for(i=0;i<f.length;i++){
- document.write("<td>"+f[i]+"</td>");
- }
- document.write("</tr></table>");
- //6. filter
- /*
- * la variable val represente l'occurrence
- */
- var filter=a.filter(function(){
- if(val.charAt(0)=="p"){
- return val;
- }
- });
- document.write("<table border=1><tr>");
- for(i=0;i<filter.length;i++){
- document.write("<td>"+filter[i]+"</td>");
- }
- document.write("</tr></table>");
- //7 sum()
- document.write([5,3,2,5].sum());
- </script>
- </script>
- </body>
- </html>