Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=windows-1250">
- <meta name="generator" content="PSPad editor, www.pspad.com">
- <title>Polia a pokrocile metody</title>
- </head>
- <body>
- <script type="text/javascript">
- //<![CDATA[
- document.write("<h1>Polia a pokrocile metody</h1>");
- document.write("<h2>I. Metoda sort()</h2>");
- pole = new Array(5,6,7,8,22,1,33,100,2);
- document.write("Pole: " + pole + "<br />");
- pole.sort();
- document.write("Zoradene abecedne: " + pole + "<br />");
- pole.sort(porovnajVzostupne); // pozor nie porovnaj()
- function porovnajVzostupne(a,b){
- return a - b ;
- }
- document.write("<h2>II. Metoda sort() s vlastnou funkciou na vzostupne zoradenie</h2>");
- document.write("Zoradene ciselne vzostupne: " + pole + "<br />");
- document.write("<h2>III. Metoda sort() s vlastnou funkciou na zostupne zoradenie</h2>");
- pole.sort(porovnajZostupne);
- function porovnajZostupne(a,b){
- return b - a ;
- }
- document.write("Zoradene ciselne zostupne: " + pole + "<br />");
- document.write("<h2>IV. Metoda reverse()</h2>");
- pole.reverse();
- document.write("Pole: " + pole + "<br />");
- document.write("<h2>V. Tvorba pola pomocou literatou</h2>");
- // mojePole = new Array();
- mojePole = []; // -> bezpecnejsi sposob, konstruktor Array() je mozne prepisat
- // a nahradit zakernym kodom napr. predstierame ze robime pole a pritom odosielame data
- document.write("Pole: " + mojePole + "<br />");
- poleCisel = [4,8,15,16,23,42]
- document.write("Pole: " + poleCisel + "<br />");
- poleStringov = ["Karol", "Jano", "Adam"]
- document.write("Pole: " + poleStringov + "<br />");
- poleRoznychTypov = ["Karol", 1, undefined, 42, "Laco", null, []];
- document.write("Pole: " + poleRoznychTypov + "<br />");
- document.write("<h2>VI. Indexovanie pomocou stringu</h2>");
- novePole = [];
- novePole["zamestnanec"] = "Karol";
- novePole["sef"] = "Fero";
- // Pouzivat asociativne polia sa nedoporucuje lepsie ukladat data do objektov
- document.write("Asociativne Pole: " + novePole["zamestnanec"] + "<br />");
- document.write("<h2>VI. Viacrozmerne a vnorene polia</h2>");
- var hierarchia = ["Laco", ["Karol", ["Eva", ["Tomas", "Peter", "Ivana"]]]];
- // Escape sekvencie \" pre lomitko
- document.write("Viacrozmerne pole: [\"Laco\", [\"Karol\", [\"Eva\", [\"Tomas\", \"Peter\", \"Ivana\"]]]]" + "<br />");
- document.write("Vnorenie Pole hierarchia[0] : " + hierarchia[0] + "<br />");
- document.write("Vnorenie Pole hierarchia[1][0]: " + hierarchia[1][0] + "<br />");
- document.write("Vnorenie Pole hierarchia[1][1][0]: " + hierarchia[1][1][0] + "<br />");
- document.write("Vnorenie Pole hierarchia[1][1][1][0]: " + hierarchia[1][1][1][0] + "<br />");
- document.write("Vnorenie Pole hierarchia[1][1][1][1]: " + hierarchia[1][1][1][1] + "<br />");
- //]]>
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment