JSFiddle - React, Tailwind, and code Playground
by Jessie Lau
JavaScript
class Underscore:
def map(self, lst, callback):
new_lst = []
for i in lst:
new_lst.push(callback(i))
return new_lst
def reduce(self, lst, callback):
total = 0
for i in lst:
total += callback(i)
return total
# your code here
def find(self, lst, callback):
# your code here
def filter(self, lst, callback):
# your code
def reject(self, lst, callback):
# your code
# you just created a library with 5 methods!
# let's create an instance of our class
_ = Underscore() # yes we are setting our instance to a variable that
# is an underscore
evens = _.filter([1, 2, 3, 4, 5, 6], lambda x: x % 2 == 0)
# should return [2, 4, 6] after you finish implementing the code above