I am working to improve recursion skills, and took a crack at the recursive function below.
However, I'm looking to improve the implementation (and thus my understanding) by eliminating the necessity of the i iterator as a second parameter to correcter. I feel like the function as is at the moment is still very iterative, if that makes sense.
How would I go about specifically eliminating this from the function, and still use use a recursive function to run the same operation successfully?
Thanks!
// Transform an array of items, correcting gramatically
var capitals = ["MaDRid", "paRIs", "SantIAgO"]
var correcter = function(array, i) {
var transform = function(city) {
return city.charAt(0).toUpperCase() + city.slice(1).toLowerCase();
}
// base case
if (array.length === i) {
return array;
}
// action
array[i] = transform(array[i]);
// recursive case
return correcter(array, i + 1);
};
correcter(capitals, 0);
Array#map