Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackhowa/truncate-string-fcc
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
https://github.com/jackhowa/truncate-string-fcc
algorithm freecodecamp javascript
Last synced: 24 days ago
JSON representation
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
- Host: GitHub
- URL: https://github.com/jackhowa/truncate-string-fcc
- Owner: JackHowa
- Created: 2017-08-09T20:12:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-09T20:38:01.000Z (over 7 years ago)
- Last Synced: 2024-11-20T21:58:11.818Z (3 months ago)
- Topics: algorithm, freecodecamp, javascript
- Language: JavaScript
- Homepage: https://www.freecodecamp.org/challenges/truncate-a-string
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Truncate a String
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
Note that inserting the three dots to the end will add to the string length.
However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.
## Requirements
* truncateString("A-tisket a-tasket A green and yellow basket", 11) should return "A-tisket...".* truncateString("Peter Piper picked a peck of pickled peppers", 14) should return "Peter Piper...".
* truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)
should return "A-tisket a-tasket A green and yellow basket".* truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)
should return "A-tisket a-tasket A green and yellow basket".* truncateString("A-", 1)
should return "A...".* truncateString("Absolutely Longer", 2)
should return "Ab...".