def create_groups(students, group_size, num_groups)
students.shuffle.cycle.each_slice(group_size).first(num_groups)
end
Yep, that's the whole thing, and it's a mouthful! Here's how it works: First, the array of students is shuffled. Then it gets called with the `cycle` method, which returns an Enumerator that will go through the end of the list, then loop back to the beginning, ad infinitum. Then `each_slice(group_size)` returns a modified Enumerator which yields arrays of the size `group_size` one at a time. Finally, `first(num_groups)` tells that Enumerator to yield an array containing the first `num_groups` arrays that it would yield.
After our usual brief blog post session, we had some free time to catch up on any work we had missed. Since I was up to date, I worked on Code School's JavaScript Roadtrip series (which I've been working through recently), and finished the final course! I then started working on a Fruitbot (for more info on the Fruitbot contest, see www.fruitbots.org) that I had been writing in Ruby, but now I want to do it in JavaScript. So I spent some time on that.
After a late lunch, we headed back in for lecture, where we covered Sinatra testing with RSpec and Capybara in much greater detail. This is seriously useful stuff, people. I like Capybara a lot already.
Skills developed: JavaScript (for me), Sinatra testing
No comments:
Post a Comment