MostlyAdequate / mostly-adequate-guide

Mostly adequate guide to FP (in javascript)
Other
23.43k stars 1.87k forks source link

fix(chapter4-exercise2): replace match function by test to fix filter… #603

Closed whatthehanan closed 3 years ago

whatthehanan commented 3 years ago

the filterQs example is incorrect. currently, match method is being used which returns an empty array in case of no match and filter method considers it as a truthy value. I have replaced match with test for intended behavior

dotnetCarpenter commented 3 years ago

match method is being used which returns an empty array in case of no match and filter method considers it as a truthy value.

I don't think that is correct. match is defined as:

// match :: RegExp -> String -> Boolean
const match = curry((re, str) => re.test(str));

That is not the string.match function you normally use in JavaScript, which returns an array. But a custom function that indeed returns a Boolean.

dotnetCarpenter commented 3 years ago

Perhaps renaming the match function to test would make it easier to grok for js developers used to string.match and regExp.test .