Daily Challenge #23

Truncate String at a Given Length

Create a function that takes a string (the string to truncate) and a number (the maximum length of the truncated string) as arguments and returns the truncated string at the given length.


truncate("Lorem ipsum dolor sit amet.", 11) ➞ "Lorem ipsum"

truncate("Lorem ipsum dolor sit amet.", 16) ➞ "Lorem ipsum"

truncate("Lorem ipsum dolor sit amet.", 17) ➞ "Lorem ipsum dolor"


  • To “truncate” means “to shorten by cutting off the top or end” .
  • If a word is truncated in the middle, discard it in the output (see 2nd example above).

Easiest way I know:

1 Like

Did you read this rule: :crazy_face:

1 Like

Oops, I didn’t read that one…

1 Like

Somebody explain how this logic works:

Convert this to “procedure with result”


In addition: if nextchar is space or nothing (text ends), if call translator.is string really differs in translations true, it is a word, if not, call worldwidedictionaryesitor.add new world (last item from wordlist).

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.