Added group.js

Added the grouping algorithm