getify / Functional-Light-JS

Pragmatic, balanced FP in JavaScript. @FLJSBook on twitter.
http://FLJSBook.com
Other
16.6k stars 1.96k forks source link

Chapter 9: Mismatch in map parameters. #172

Closed infinityfye closed 1 year ago

infinityfye commented 5 years ago

In the Map section of Chapter 9, after the implementation of map you give a note on parameter order, the example given has the parameters in the wrong order.

map( ["1","2","3"], unary( parseInt ) );
// [1,2,3]

I believe it should be

map(unary( parseInt ),  ["1","2","3"] );
// [1,2,3]

Please forgive me if I'm mistaken.

getify commented 5 years ago

You're correct, thanks for catching that!

infinityfye commented 5 years ago

The parameter ordering mismatch is also echoed in the first example in Method Vs Standalone section. The current code is

[1,2,3,4,5]
.filter( isOdd )
.map( double )
.reduce( sum, 0 );                  // 18

// vs.

reduce(
    map(
        filter( [1,2,3,4,5], isOdd ),
        double
    ),
    sum,
    0
);                                  // 18

I believe it should be

[1,2,3,4,5]
.filter( isOdd )
.map( double )
.reduce( sum, 0 );                  // 18

// vs.

reduce(
    sum,
    0,
    map(
        double,
        filter( isOdd, [1,2,3,4,5] )
    )
);                                  // 18

I realise that this is mostly to point out the difference in the API, which is why I didn't create a new Issue.