Firas Mock Interview Questions
Firas Mock Interview Questions
Consider the `map` function, a fundamental concept in functional programming that transforms
each item in a collection according to a specified operation, resulting in a new collection with the
transformed items. How would you approach designing and implementing your version of the
`map` function from scratch in Python, JavaScript, or any other programming language you
prefer? Consider how your function will handle edge cases, such as empty collection. Describe
your implementation strategy and the thought process behind your design decisions.
● accumulator: This is a value that accumulates the results of each function call. It's like a
running total or combined result that gets updated each time the function is called.
● currentValue: This is the current element being processed in the array or collection.
● newValue: This is the new value of the accumulator after combining it with the current
value.
In essence, the reducer function takes two things — an ongoing total (accumulator) and the
current item (currentValue) — and combines them to form a new ongoing total. This process
repeats for each item in the collection, ultimately resulting in a single value that represents the
culmination of combining all items in the collection according to the specific logic defined in the
reducer function.
Bonus Question: Find the Second Largest Element
Problem Statement:
Using our custom reduce function, write code that finds the second largest element in a list of
positive integers.
Note: Assume the list contains at least two unique positive integers.