You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* We call the .toLowerCase() method on the string of text received to convert the entire sentence to lowercase. We also chain the .split() method in sequence to divide the lowercase sentence into an array of words as shown below. This array is stored as wordsArray
344
+
</p>
345
+
<p>
346
+
347
+
* Next, using the .foreach() method, we iterate through every word(element) in the array and execute a function on it.
348
+
* The function takes the first letter of the word and turns it to uppercase using the .toUpperCase() method. To retrieve the remaining part of the word in lowercase, we use the .slice() method to slice the string starting from position 1 till the end.
349
+
350
+
* We combine the transformed first letter and the sliced section together to form the capitalized word which we push into our array of capitalized words capsArray.
351
+
352
+
* After this process has being carried out for every word, capsArray now holds the capitalized version of every word in the sentence
353
+
354
+
* Finally .join() method is used
355
+
</p>
356
+
357
+
324
358
2. Using .map and .slice method:
325
359
The .map method is used to create a new array with the results gotten from calling a provided function on every element in the array on which it is called.
0 commit comments