The Enumerable.eachSlice method , or the documentation is faulty!  Just 
adjust the src attribute to point to your copy of Prototype and try this to 
see why!

It's because the slice native array method always returns an array every 
time it's called, so the output will never be:

[['Sunny', 'Audrey', 'Matt'], ['Amelie', 'Will']], but an array with two 
undefined values!

.Either the iterator function should act accordingly as in the oroginal 
inGroupsOf method, or preferably the two methods should be adjusted for 
something like the ones below:
Probably you will never use these methods, but they are parts of the public 
interface, so they should work properly!

  function eachSlice(number, iterator, context) {
    var index = -number, slices = [], array = this.toArray();
    if (number < 1) return array;
    while ((index += number) < array.length)
      slices.push(array.slice(index, index+number).collect(iterator, 
    return slices;

function inGroupsOf(number, fillWith, iterator){
    fillWidth = Object.isUndefined(fillWith)? null : fillWith;
    var tmp = this.eachSlice(number, iterator), res = [];
    tmp.each(function(arr, index){
          while(arr.length < number){
      return res;  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="";>

 <meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
    <title>Faulty eacSlice method test</title>

<script type="text/javascript" language="javascript" 
<script type="text/javascript" language="javascript">
    var students = [
  { name: 'Sunny', age: 20 },
  { name: 'Audrey', age: 21 },
  { name: 'Matt', age: 20 },
  { name: 'Amelie', age: 26 },
  { name: 'Will', age: 21 }
 var student_names = students.eachSlice(3, function(student, count) {
  if(typeof == 'undefined'){alert(count + ' -student is an 
for(var i = 0; i < student_names.length; i++){
    alert(typeof student_names[i]);

   <div>Nothing to see here.</div> 

You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to