Это видео недоступно.
Сожалеем об этом.

Here's a smart one liner for you!

Поделиться
HTML-код
  • Опубликовано: 21 июн 2023
  • This line of code uses a pretty ingenious way to manipulate the range of a number. In this short, we take a quick look to understand how it works!
    While this is not really good programming practice because it puts too many operations on one line (as opposed to using if-statements), it takes quite a smart approach at solving this problem!
    -----
    Want to contribute to the channel? Consider using the "Super Thanks" feature above, or visit my website at nerdfirst.net/... to find alternative ways to donate. Thank you!
    -----
    Disclaimer: Please note that any information is provided on this channel in good faith, but I cannot guarantee 100% accuracy / correctness on all content. Contributors to this channel are not to be held responsible for any possible outcomes from your use of the information.

Комментарии • 4

  • @Eyetrauma
    @Eyetrauma Год назад

    I’ve become so mindbroken by interview quizzes that nowadays when I face a problem that has a straightforward series of conditionals that would satisfy the problem I find myself sitting there obsessing over whether or not there isn’t some modulo, shift or other operation trick that would do it instead. Sure it’s less readable, but what if leetcode types flex on me oh naurrrrr

    • @NERDfirst
      @NERDfirst  Год назад

      Oh I absolutely get you. I did code golf at one point and it absolutely ruined my ability to write "normal" code for a while. Gotta rein it in and remind yourself not everything needs to be solved using a fancy big brain move.

  • @kevintyrrell7409
    @kevintyrrell7409 Год назад +1

    In my opinion I think if the one-liner was documented with:
    // clamps value to domain [0, 10]
    then the functional approach would be objectively more clear and concise. Of course the if statement approach is faster due to lack of the function call overhead.

    • @NERDfirst
      @NERDfirst  Год назад +1

      Hello and thank you for your comment! I can definitely see how a good comment can help making the statement easier to understand, though I wouldn't necessarily say it is _objectively_ better if you think about it from a cognitive load standpoint - Two if-statements are effortless to understand, debug, and adapt. The functional method takes a moment's pause.