0
Typescrip counting words in string HELP :)
I need to count words in string, if there are 2 words i need to get the first letters from those two words and if there is one word i needbto get the first two letters from the word.
4 Respuestas
+ 1
Try to split the problem into small pieces so you can solve it .
1- first split the string ( use the split method) by space , so it will returns an array of words .
2- iterate through that array and return the first letter
Hope this Helps
+ 1
Have you solved this Kate Atanasoska ?
Similar to what Med said, a good first step is to split the string by a space which returns an array of a word, or words.
You can then get the number of words by getting the length of the array.
Then, you can use some conditional logic like an if statement: if one word...else...
You can use an index number in square brackets to take a word out of the array. Then on the word string, you can either use an index number in square brackets again to get an individual letter or use a string method like slice().
+ 1
Thank you, i did it.
+ 1
Nice 😊 well done