Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
7Raiden8756ys[0].upper() + s[1:]
This you don't change the capitalization of the other letters! otherwise
s[0].upper() + str(s[1:]).lower()
This is only pseudo code it's probably non-legal python! -
Wow! This community is so polite!
No one called that one-liner a piece of crap 😂 -
!i is beautiful! Better than having an initial state going “bool didCapitalizeYet”
I found it beautiful. It’s like something that looks complex and it’s familiar on your concepts.
But that is a clean initial state statement.. I’m gonna use it one time !i -
@irene
myString = myString.split(" ");
for (var i = 0, x = myString.length; i < x; i++) {
if (myString[i]) {
myString[i] = myString[i][0].toUpperCase() + myString[i].substr(1).toLowerCase();
}
};
myString.join(" ");
Spaghetti enough? -
@growling 🙌 hallelujah! Someone saw the single reason why I liked that ugly creation of mine!
-
I know it’s off topic, but
str.split(‘ ‘).reduce((acc, cur) => acc + ‘ ‘ + cur[0].toUpperCase() + cur.slice(1).toLowerCase(), ‘’) -
musician6656y@irene thats because you are used to it.
Imperative programming isnt easier. Its just that you programmed it 50000 times. -
@irene in my phone’s suggested news section, I saw an article about most of Microsoft software updates are fixing memory leak issue. And they blame the C/C++ are the main reason 😈 (could be filter bubble)
-
musician6656y@irene Not harder for YOU since you are so used to it. If you started with functional programming for example the imperative approach would look harder
-
musician6656y@irene at least I fail to see how telling a computer how to iterate, how to acces each element, modify each element etc. is more readable than for example a filter(isEven).
Pretty sure the 2nd approach could be understood by non programmers as well. -
musician6656y@irene you are 100% right here but I take readability over micro optimization every day. Unless its either something very close to the hardware or something like a sort algorithm.
Also some languages are really good at compiling stuff like map and reduce. -
-
musician6656y@sunfishcc ?
Also I'm talking about paradigms not languages.
Not a fan of pure js either. Cant stand languages without types. -
@irene i got first line from a bug. Where null array in js doesn’t run map. So I have to fill some arbitrary value. Then use the index... but... hey... 🤦♂️ that’s enough
-
@retnikt it just a predefined function. You can include package like lodash in Js to do the same thing.
But when file size is an issue, many programmer preferred to write their own one liner. -
@irene there’re many articles about the performance benefits on Array buildin functions vs for loop.
Plus, you feel something is wrong if for loop is used in python and JS, right?! 😑 -
I prefer downloading a 400mb npm package for capitalizing the first letter of a string
Day in a life of a JS developer.
rant
masterpiece
oneliner
javascript