136

Day in a life of a JS developer.

Comments
  • 21
    s[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!
  • 14
    Wow! This community is so polite!
    No one called that one-liner a piece of crap 😂
  • 6
    @arturgrigio it is a piece of crap
    It is js
  • 7
    !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
  • 4
    myString.charAt(0).toUpperCase() + myString.slice(1).toLowerCase()
  • 6
    @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?
  • 2
  • 3
    @mundo03 wait till I post some PHP
  • 2
    @growling 🙌 hallelujah! Someone saw the single reason why I liked that ugly creation of mine!
  • 1
    @finiteAutomaton that’s a great one-liner!
  • 0
    @arturgrigio PHP7 is better than Js
  • 1
    I mean.. still 10x better than string manipulation with c lol
  • 3
    I know it’s off topic, but
    str.split(‘ ‘).reduce((acc, cur) => acc + ‘ ‘ + cur[0].toUpperCase() + cur.slice(1).toLowerCase(), ‘’)
  • 4
  • 1
    @irene bullshit
    Thats only because you know it better
  • 2
    @irene how to write 1 liner for capitalise each word in a string in C? 🤔
  • 0
    @irene thats because you are used to it.
    Imperative programming isnt easier. Its just that you programmed it 50000 times.
  • 1
    @irene then it’s harder. No doubt 😼
  • 1
    @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)
  • 0
    @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
  • 1
    @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.
  • 4
    @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.
  • 2
    @musician js101:
    Don’t write: Array(4).fill(0).map((_v, i) => i + 1)
    Just write [1, 2, 3, 4]
    🤦‍♂️
  • 0
    @sunfishcc ?
    Also I'm talking about paradigms not languages.
    Not a fan of pure js either. Cant stand languages without types.
  • 3
    Python
    s.title()
    So beautiful.
  • 1
    @musician js is strong type language btw.😏
  • 0
    @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
  • 1
    @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.
  • 0
    @irene 🥺but how can you know map can’t iterate null array? 🙄
  • 0
    @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?! 😑
  • 0
    @irene I’m that kind guy who use js to generate my password 🤔
  • 0
    @irene nah. I run a script use node.js to generate passwords 😈
  • 0
    +1 for Mona Lisa
  • 1
    Vala da best on this!
    str = str[0].up () + str[1:];
  • 0
    I prefer downloading a 400mb npm package for capitalizing the first letter of a string
Add Comment