Array.map I - strings

Easy
36
5
65.1% Acceptance

Write a function called mapToUppercase(names), which takes an array of strings called names as its argument. This function should return a new array with all of the strings transformed to UPPERCASE.

Instructions

  • The input array names will contain only strings.
  • Do not modify the existing array. Return a new array with transformed strings.
  • If the input array names is empty, then return an empty array.

Example test cases

1const names1 = ['john', 'mary', 'bob', 'jane']; 2const uppercasedNames1 = mapToUppercase(names1); 3console.log(uppercasedNames1); 4// Output: ['JOHN', 'MARY', 'BOB', 'JANE'] 5 6const names2 = ['Alice', 'Bob', 'Charlie']; 7const uppercasedNames2 = mapToUppercase(names2); 8console.log(uppercasedNames2); 9// Output: ['ALICE', 'BOB', 'CHARLIE'] 10 11const names3 = []; 12const uppercasedNames3 = mapToUppercase(names3); 13console.log(uppercasedNames3); 14// Output: []

Hints

  • You can create a new array, loop over the input array names and push the transformed element to the new array.
  • You can use the built-in method .map() method.
  • Use the toUpperCase() method to transform a string to UPPERCASE.