Skip to content

Instantly share code, notes, and snippets.

@UniBreakfast
Created October 1, 2021 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UniBreakfast/1d9f3b7115e268b67f1130c7b667d8dd to your computer and use it in GitHub Desktop.
Save UniBreakfast/1d9f3b7115e268b67f1130c7b667d8dd to your computer and use it in GitHub Desktop.
Higher order methods with thisArg usage
prices = [10, 25, 70, 100, 120]
discountFuncs = [5, 10, 25, 30]
.map(num => x => '$' + (x / 100 * (100-num)).toFixed(2))
discountFuncs.map([].map, prices)
// (4) [Array(5), Array(5), Array(5), Array(5)]
// 0: (5) ['$9.50', '$23.75', '$66.50', '$95.00', '$114.00']
// 1: (5) ['$9.00', '$22.50', '$63.00', '$90.00', '$108.00']
// 2: (5) ['$7.50', '$18.75', '$52.50', '$75.00', '$90.00']
// 3: (5) ['$7.00', '$17.50', '$49.00', '$70.00', '$84.00']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment