Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.flowRight() method is used to create a new composite function that invokes the provided functions from right to left, where each of the successive invocations is provided the return value of the previous. It is almost the same as _.flow() method.
Syntax:
_.flowRight( funcs )
Parameters: This method accepts a single parameter as mentioned above and described below:
- funcs: This parameter holds the functions to invoke. It is an optional parameter.
Return Value: This method returns the new composite function.
Example 1:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Function to calculate the // Cube of a number function cube(number) { return number * number * number; } // Using the _.flowRight() method var multiplycube = _.flowRight([cube, _.multiply]); // Printing the output console.log(multiplycube(2, 3)); |
Output:
216
Example 2:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Function to calculate the // double value of a number function doubled(number) { return number * 2; } // Using the _.flowRight() method var adddoubled = _.flowRight([doubled, _.add]); // Printing the output console.log(adddoubled(6, 8)); |
Output:
28