← Back to challenges

A Redundant Function

JavaScriptHardlanguage_fundamentalsfunctional_programmingclosures

Instructions

Write a function redundant that takes in a string str and returns a function that returns str.

Examples

const f1 = redundant("apple")
f1() ➞ "apple"

const f2 = redundant("pear")
f2() ➞ "pear"

const f3 = redundant("")
f3() ➞ ""

Notes

Your function should return a function, not a string.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: RegEx Exercise: An empty string