Functional-Light-JS icon indicating copy to clipboard operation
Functional-Light-JS copied to clipboard

Chapter 9: Mismatch in map parameters.

Open infinityfye opened this issue 7 years ago • 2 comments

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.

infinityfye avatar Oct 28 '18 14:10 infinityfye

You're correct, thanks for catching that!

getify avatar Oct 28 '18 14:10 getify

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.

infinityfye avatar Oct 31 '18 15:10 infinityfye