flowyroll / lodash.lua

lodash inspired library for lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

groupBy keys become strings; example is not reproducible

drauschenbach opened this issue · comments

I'm having trouble reproducing the groupBy example:

_.print(_.groupBy({4.3, 6.1, 6.4}, function(n)
   return math.floor(n)
 end))
 --> {[4]={4.3}, [6]={6.1, 6.4}}

What I get instead is a result keyed by strings instead of numbers:

$ lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> _ = require 'lodash'
> _.print(_.groupBy({4.3, 6.1, 6.4}, function(n) return math.floor(n) end))
{["6"]={6.1, 6.4}, ["4"]={4.3}}

I removed the call to _.str() in the groupBy function and verified that the results are now correct.

I also notice that the unit tests are asserting the wrong key datatypes, which is not consistent with the source data or the README example.

Thanks for reporting this. Would you please create a pull request with the fix?