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.

Examples

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"

Notes

  • 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).
2 Likes

Easiest way I know:
Screenshot_20191004-122129_Chrome

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:

Challenge:
Convert this to “procedure with result”

3 Likes

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.