Bird
0
0

Given a curried lambda calc = ->(a, b, c) { a * c + b }.curry, how do you create a new function that multiplies by 10 and adds 5?

hard📝 Application Q9 of 15
Ruby - Functional Patterns in Ruby
Given a curried lambda calc = ->(a, b, c) { a * c + b }.curry, how do you create a new function that multiplies by 10 and adds 5?
Anew_func = calc.call(10).call(5).call(1)
Bnew_func = calc.call(10).call(1).call(5)
Cnew_func = calc.call(10).call(5)
Dnew_func = calc.call(10).call(0).call(5)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the lambda parameters

    The lambda calculates a * c + b. To create a new function that multiplies its input by 10 and adds 5, fix a=10 (multiplier) and b=5 (addend).
  2. Step 2: Apply arguments in order

    Calling calc.call(10) fixes a, then call(5) fixes b, returning a new function f(c) { 10 * c + 5 }.
  3. Final Answer:

    new_func = calc.call(10).call(5) -> Option C
  4. Quick Check:

    Correct argument order fixes function [OK]
Quick Trick: Apply arguments in lambda parameter order [OK]
Common Mistakes:
  • Mixing argument order
  • Skipping arguments causing errors
  • Misunderstanding which argument is which

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes