Last active
March 13, 2021 11:32
-
-
Save joram77/a563b822b150309fbfdbf23d1dd2f136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Substring of a given string until the first space occuring before the given max length. **/ | |
function substringUntilSpace(start, length, s) { | |
let trimmedString; | |
if (s.length > length) { | |
trimmedString = s.substr(start, length); | |
if (s.charAt((start + length)) != ' ') { | |
const lispace = trimmedString.lastIndexOf(" "); | |
if (lispace != -1) trimmedString = trimmedString.substr(start, lispace); | |
} | |
} else trimmedString = s; | |
return trimmedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment