take n values from a javascript generator