Solution to Find Mutual Friends
The solution to MapReduce in JavaScript for the problem "Find Mutual Friends"
We'll cover the following...
Putting it all together
Now that all functions are working and ready, let’s jump into the final mapreduce
function. This will be the simulation of our MapReduce framework. Look at the code below.
Press + to interact
// Finalfunction mapreduce (friends) {var initial = setup(friends);var mapped = mapper(initial);var grouped = group(mapped);var reduced = reducer(grouped);return reduced;// return an object {(man,friend): [Friends]}}var arr = [['A', 'B'], ['A', 'C'],['A', 'D'], ['B', 'C'],['B', 'D'], ['B', 'E'],['C', 'D'], ['C', 'E'],['D', 'E']];console.log(mapreduce(arr));
The code above calls a series of functions in the ...