the MDN page for the flatten() method has this snippet of code
(function flattenDeep(arr1){
return arr1.reduce((acc, val) =>
Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
})(arr1);
What I'd like to know is
- Why is the entire function encapsulated in
()
? - What does
(arr1)
after the function do? - What is the name for the
something ? doThis : orDoThis
algorithm?