We have to write a function that returns the given array switching every word in uppercase format. No loops are allowed (would make things much easier).
This is what I came up with so far but only half of the output seems to capitalize and I don’t really understand why. this is my code
function capitalize(word) {
let newArr = word.map(word => {
return word.toUpperCase();
});
return newArr;
}
this is another iteration I tried
function capitalize(word) {
let newArr = word.map(el => {
return el.toUpperCase();
});
}
Here is the code we are given to test and display the function :
// Here is some code to test and display your function output:
// (you must modify it to test out your code but /! do not deliver it /! ). Only deliver your function
const result = ["CHANGE", "this", "array", "BY", "ThE", "RESULT", "oF", "youR", "FUNCTION", "TO", "test", "IT", "OUT"]
displayResult(result)
Once executed the words 1, 4, 6, 9, 10, 12 & 13 are correct but not the rest.
When I put the functions I created in Python Tutor it seems to work fine so I’m having a hard time understanding where the error is
Any and all suggestions are welcomed, thank you!
2
Answers
Just return the given array after using the map method.
Here is an example.
Seems you should transform the elements in-place, use
forEach()
: