jlepird / next-gen-assignments

Source code for
https://af-talent-marketplace.app.cloud.gov
Other
2 stars 0 forks source link

Invert and other helper functions #4

Closed johangithub closed 7 years ago

johangithub commented 7 years ago

I saw the use of custom invert function here. There's a javascript library called lodash.js which will help you with array/object manipulation such as invert. I'd recommend going through the doc here. Your code will go from this:

var invert = function (obj) {
          var new_obj = {};
          for (var prop in obj) {
                if (obj.hasOwnProperty(prop)) {
                    new_obj[obj[prop]] = prop;
                }
            }
      return new_obj;
        };
        var invertedMonths = invert(monthDisplay);

to this:

var invertedMonths = _.invert(monthDisplay)
jlepird commented 7 years ago

Done-- good find on the library!