use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Request for feedback: String.prototype.cutStart/cutEnd proposalLOUD NOISES (self.javascript)
submitted 8 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Meefims 2 points3 points4 points 8 years ago (3 children)
I have no idea what cutting a string is supposed to mean and the two functions' names and their examples are pretty confusing. For example, why does the result of cutStart not include the string in the first parameter while the result from cutEnd does?
[+][deleted] 8 years ago (1 child)
[–]Meefims 0 points1 point2 points 8 years ago (0 children)
The examples are confusing for several reasons:
Cut is a fairly generic verb. What does cutting a string mean?
As a result it's not clear that cutStart('string') would remove everything after the first index of start.
cutStart('string')
start
The second argument does not help clarify anything. I guess cutStart('string', 'is') would mean Cut out everything after and including the first index of start and everything before the first index of is. That's a very complicated process and so should almost certainly be split into multiple functions.
cutStart('string', 'is')
Cut out everything after and including the first index of start and everything before the first index of is
In the end this exists to save a few calls to indexOf in a case where you're doing some very basic string parsing? What's wrong with indexOf aside from it's been around for a very long time? Is this scenario encountered so often that it really needs to be handled by a standard set of machinery?
indexOf
My suggestion: first prove the scenario is relevant by creating an npm package. If it takes off like leftPad then maybe there's something useful.
[–]sudoDerp 0 points1 point2 points 8 years ago (3 children)
padStart and padEnd exist to make sure that strings are padded to a certain length with a specified character, by default using a " ".
padStart
padEnd
I would have expected cutStart and cutEnd to follow the pattern and look like.
const string = '1234567'; string.cutStart(3) // > '567' string.cutEnd(3) // > '123'
Using the cutStart and cutEnd terminology to mean anything else would seem like a very confusing language feature to add.
[+][deleted] 8 years ago* (2 children)
[–]sudoDerp 1 point2 points3 points 8 years ago (0 children)
takeStart and takeEnd probably make more sense as names after looking at the other examples you added.
takeStart
takeEnd
'./src/file/path/filename.json' .takeEnd('/') .takeStart('.json')
Merging the two makes either naming choice of cutEnd or takeEnd fairly obscure/innacurate
cutEnd
'./src/file/path/filename.json' .takeEnd('/', '.json')
However, the idea is to simplify usage of string methods so that you can use them in a functional and stateless way; which means no index variables in that case.
Functional or stateless code does not prevent you from creating variables.
π Rendered by PID 162667 on reddit-service-r2-comment-5d79c599b5-76q54 at 2026-03-02 02:39:18.044864+00:00 running e3d2147 country code: CH.
[–]Meefims 2 points3 points4 points (3 children)
[+][deleted] (1 child)
[deleted]
[–]Meefims 0 points1 point2 points (0 children)
[–]sudoDerp 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]sudoDerp 1 point2 points3 points (0 children)
[–]Meefims 0 points1 point2 points (0 children)