Adder Functions

Published by caloizou in

Create the function defined_adder which takes a number num (integer or float) as an argument, and returns another function. This returned function should take another number (integer or float) as an argument and add the original num to that number, then return it.

Also create the function undefined_adder, which is an exact replica of defined_adder, except in the format of a lambda (undefined function).

Examples

add3 = defined_adder(3)
add3(5) ➞ 8            (3 + 5 = 8)
add3(2) ➞ 5            (3 + 2 = 5)

add2_half = undefined_adder(2.5)
add2_half(8) ➞ 10.5     (2.5 + 8 = 10)
add2_half(2.5) ➞ 5       (2.5 + 2.5 = 5)

-- BONUS (not necessary for challenge completion)
add_minus3 = defined_undefined_adder(-3)
add_minus3(-2) ➞ -5            (-3 + -2 = -5)
add_minus3(8) ➞ 5               (-3 + 8 = 5)

Notes

  • The numbers passed as arguments can be any real number.
  • In the defined_adder function, you must only use defined functions.
  • In the undefined_adder function, you must only use undefined (lambda) functions.
  • There are three different ways of completing this challenge. For a bonus, write the last (code commented out in Code tab). Note: all functions should be different from one-another.
  • To complete this challenge, you need only create the defined_adder and undefined_adder functions. If you want to ignore the bonus challenge, please do.
Watch a quick demo on how Edabit works.