fordth / jinqJs

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.
Other
93 stars 29 forks source link

Fixed: Need to add a value instead of a whole row #14

Closed gpminsuk closed 8 years ago

gpminsuk commented 8 years ago

Need to add a value instead of a whole row

fordth commented 8 years ago

Thank you for the contribution. I will run it through some unit tests. If I remember correctly isSimple represent a simple type (number, string, etc..), therefore not having a field. If you can give me an example of an issue you are addressing, I will look into it. -Tom

gpminsuk commented 8 years ago

Hi Tom, Thanks for developing this project first. The problem happens when source data is array of array instead of array of object. So if I have var data = [[0, 0, 0]] and do new jinqJs().from(data).select(0) It returns [0, 0, 0] whereas expected result is 0

I read the code more after reading your reply. I think the problem could be isObject function where it returns false for arrays.

By the way, why are simple values considered from the first place? If each row is a simple value, there's no point selecting..?

-Minsuk

fordth commented 8 years ago

I will take a look at the isObject function this weekend, thanks. The reason for handling simple values is to provide sorting, aggregate, unions, etc.. on simple arrays,

fordth commented 8 years ago

Hey gpminsuk, what a great find! I changed the isObject method and it passes all the unit tests. You can now do something like this: new jinqJs() .from([[1,2,3,4,3,5], [6,7,8,9]]) .distinct() .select(2) This will now return the second index item in each of the arrays.

I am working on creating a release to include the change thanks again!

-Tom