InterviewSolution
Saved Bookmarks
| 1. |
Modify below code using Dependency Injection. |
|
Answer» 35 Higher order functions are simply functions that can EITHER accept functions or closures as arguments or return a function/closure. Higher Order Functions are very useful and powerful and help us to write more elegantly and maintainable code. Those functions are Map, Filter, Reduce, Sort, CompactMap etc. let result = [listOne.compactMap({ $0}),listTwo.compactMap({ $0})].flatMap({ $0}).reduce(0) { $0 + $1 }First compact map removes NIL ELEMENT from the array. Then by using a flat map, we COMBINE these two arrays. And finally, reduce function will help to get the sum of array elements. |
|