JSFiddle - React, Tailwind, and code Playground

by Rob Lardy

JavaScript

/*
Month names

Write a function that will return the Month name for a given number (1-12). 

You will want to make a closure to close over the array of month names that you will likely need in order to map 1-12 to a name. So because of this the function should RETURN another function (this is key to the closure). 

*/


var month_name = (function() {
    
    var monthNames = ["January", "February", "March"];
    
    return function(i) {
        
        return monthNames[i-1];
        
    }
    
}());
console.log(month_name(1));
// → March