Skip to content

Commit b19f8de

Browse files
author
Neelesh Shetty
committed
Medium
1 parent a251adc commit b19f8de

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

22.RedundantFunction.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A Redundant Function
2+
3+
// Write a function redundant that takes in a string str and returns a function that returns str.
4+
5+
function redundant(str) {
6+
return function () {
7+
return str
8+
}
9+
}
10+
11+
const f1 = redundant("apple")
12+
const f2 = redundant("pear")
13+
const f3 = redundant("")
14+
15+
console.log(f1()) // f1() ➞ "apple"
16+
console.log(f2()) // f2() ➞ "pear"
17+
console.log(f3()) // f3() ➞ ""

0 commit comments

Comments
 (0)