SImple collection functions in JavaScript