russplaysguitar / UnderscoreCF

An UnderscoreJS port for Coldfusion. Functional programming library.
http://russplaysguitar.github.com/UnderscoreCF/
MIT License
89 stars 38 forks source link

Fix findWhere search when using search struct with multiple keys #57

Closed detarmstrong closed 7 years ago

detarmstrong commented 7 years ago

I noticed findWhere wasn't living up to it's documented behavior to "Looks through the collection and returns the first value that matches all of the key-value pairs listed in properties." and was instead returning the first struct that matched any of the key value pairs listed in properties. This should fix that.

russplaysguitar commented 7 years ago

Thanks for your interest in contributing! The intent of this project is to be a port of Underscore.js, so each method should function the same. In Underscore.js, does findWhere() function the same as the modified version?

detarmstrong commented 7 years ago

Yes, this fiddle demonstrates how all key-value pairs must match to return a result : http://jsfiddle.net/BwHxv/702/

russplaysguitar commented 7 years ago

Ah, yeah, this makes sense. The old logic was always returning the first item in the list. The findWhere tests each expected the first element, which is why this went unnoticed for so long. Thanks for the fix, good catch!

Note: the existing broken tests are caused by an unrelated issue, so I'm going to merge this in.