This can be useful if you want to pick out or limit the size of words in a string and sometimes gets set as a coding challenge for interviews.
Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!
If you’re looking for some basic algorithm scripting to find the longest word in a string, there’s no easier way than using a sort function on the words in the string.
But first, we need to make sure we have the words of the string set out in an array. To do this, we’ll need to use the split() function to transform our string in to an array of words. We’re going to make an assumption that words are separated by a space in order to split our string up.
Xem thêm bài viết khác: https://vinhtrinh.com.vn/cong-nghe/