Prototype - Enumerable zip() Method


Advertisements


This method zips together 2 + sequences, providing an array of tuples.

Each tuple contains one value per original sequence. Tuples can be converted to something else by applying the optional iterator on them.

Syntax

Iterator.zip(Sequence);

Return Value

Returns an array of zipped values.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var firstNames = ['Justin', 'Tobie', 'Christophe'];
            var lastNames = ['Palmer', 'Langel', 'Porteneuve'];
            var zipped = firstNames.zip(lastNames);

            alert("zipped values: " + zipped.inspect());
            var zipped = firstNames.zip(lastNames, function(a) { 
               return a.join(' '); 
            })
            alert("zipped values: " + zipped.inspect());
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

Output


prototype_enumerating.htm

Advertisements