Which Function Returns the Larger Number?

Published by bangyen in

Your function will be passed two functions, f and g, that don't take any parameters. Your function has to call them, and return a string which indicates which function returned the larger number.

  • If f returns the larger number, return the string f.
  • If g returns the larger number, return the string g.
  • If the functions return the same number, return the string neither.

Examples

larger({5}, {10}) ➞ "g"

larger({25}, {25}) ➞ "neither"

larger({505050}, {5050}) ➞ "f"

Notes

This exercise is designed as an introduction to higher order functions (functions which use other functions to do their work).

Watch a quick demo on how Edabit works.