_.map – Javascript Problem

This is an exercise taken from the Javascript: From Fundamentals to Functional course by Bianca Gandolfo on FrontEnd Masters.  The characters are taken from a game of Clue – a murder whodunit…

Here I have recreated a map() method in a slightly different way.  Instead of attaching it to the array prototype, I created it as a function which can take in either an array or an object and process it.

On line 3, I test to see if the “list” passed in is an array.  If so, I use a for loop to process the array.  If it is not an array, I assume it is an object and use a for…in loop to process it.  It returns an array of objects called suspectsList in either case.


Leave a Reply

Your email address will not be published.