• Sign Up
    Time to claim your honor
  • Training
  • Practice
    Complete challenging Kata to earn honor and ranks. Re-train to hone technique
  • Freestyle Sparring
    Take turns remixing and refactoring others code through Kumite
  • Community
  • Leaderboards
    Achieve honor and move up the global leaderboards
  • Chat
    Join our Discord server and chat with your fellow code warriors
  • Discussions
    View our Github Discussions board to discuss general Codewars topics
  • About
  • Docs
    Learn about all of the different aspects of Codewars
  • Blog
    Read the latest news from Codewars and the community
  • Log In
  • Sign Up
justinddaniel Avatar
Name:Unknown
Clan:Flatiron School
Member Since:Jan 2018
Last Seen:Oct 2023
Profiles:
Following:509
Followers:506
Allies:504
View Profile Badges
  • Stats
  • Kata
  • Collections
  • Kumite
  • Social
  • Discourse
  • Conversations (84)
  • Replies
  • Authored
  • Needs Resolution
  • Custom User Avatar
    • zali30
    • commented on "Do I get a bonus?" javascript solution
    • 2 months ago

    real🤣

  • Custom User Avatar
    • kennylun
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 10 months ago

    str has assigned as an empty string in the first line of code, and it won't go in to the for loop when 1 <= 0. So it'll directly return ""

  • Custom User Avatar
    • emberborja
    • commented on "Pillars" javascript solution
    • 11 months ago

    why are you allergic to spaces?

  • Custom User Avatar
    • nanangandrianto
    • commented on "Pillars" javascript solution
    • 15 months ago

    awesome. same with me.

  • Custom User Avatar
    • RB38
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 16 months ago

    Oke, but what is returned when count_sheep(0) is executed? Not an empty ""...

  • Custom User Avatar
    • lowtist
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    i literallt did exactly this and it didnt pass me

  • Custom User Avatar
    • RaW6995
    • commented on "Pillars" javascript solution
    • 2 years ago

    Please could you explain the need to -1 when multiplying the distance with num_pills?

  • Custom User Avatar
    • bmagaziner
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    what a beautifully thorough and graspable response. thank you so much.

  • Custom User Avatar
    • RileyHunter
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    This is known as an "arrow" function in JS, and for this particular example there isn't really a point. For simple cases there isn't a difference, it's just a stylistic choice. Many devs (including myself) prefer the arrow syntax because it's concise and much more readable in certain contexts. For example if I had a collection of things and I wanted to filter them by some criteria, I could write this with traditional "function declaration" syntax:

    let myCollectionOfThings = [<whatever>];
    
    function filterFunc(thing) {
      return thing.fitsSomeCriteria;
    }
    
    let myFilteredCollection = myCollectionOfThings.filter(filterFunc);
    

    or with function expression syntax I could write:

    let myCollectionOfThings = [<whatever>];
    let myFilteredCollection = myCollectionOfThings.filter(function (thing) {
      return thing.fitsSomeCriteria
    });
    

    or with arrow syntax I could simply write:

    let myCollectionOfThings = [<whatever>];
    let myFilteredCollection = myCollectionOfThings.filter(thing => thing.fitsSomeCriteria);
    

    Now for more complex cases there are deliberate differences in functionality - arrow functions cannot be generators or constructors, for example, and they bind differently. It's okay if you're not familiar with those concepts yet, and it's definitely okay to be confused in general! You should become familiar with this syntax though; even if you dislike it yourself it's still going to pop up all over the place in other people's code.

    Edit: There is a broader point to think about, too; in JavaScript functions are much like any other variable value and we often want to pass functions around. When filtering an array, as in the example above, the filter() function requires that you give it a function to apply to each element. To give a function to another piece of code, we often have to make that function into a variable.

  • Custom User Avatar
    • bmagaziner
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    whats the point of naming a variable initialized as a function? i find that syntax incredibly confusing.

  • Custom User Avatar
    • road2rhodes
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    When I first came to CodeWars, I was completely stumped. I have come back a few weeks later, after practicing with Javascript for hours each day and now I've done several of them. I say this to say, give it time. Even seasoned programmers get stuck on problems.

  • Custom User Avatar
    • brylsherbert
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    Amazing! tried it for hours but couldnt solve it because I tried to return something inside the for loop and always get 1 sheep...and used if/else (num !== 0) { forloop }
    didnt need if else in this hahahahaha got my brain juiced up

  • Custom User Avatar
    • Natnae-l
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    same!!!

  • Custom User Avatar
    • DanielT-117
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    I'm confused. Since i = 1, if you put in the argument (function(1)) then "i <= num" becomes true. So it would increase i by 1. Therefore, i = 2 and the output would be "1 sheep...2 sheep", no? not "1 sheep...". if someone could explain this please. That would be appreciated.

  • Custom User Avatar
    • joewhocodes
    • commented on "If you can't sleep, just count sheep!!" javascript solution
    • 2 years ago

    Yes if you are going to use template literals, you need to use backticks!

  • Loading more items...
  • Ā© 2025 Codewars
  • About
  • API
  • Blog
  • Privacy
  • Terms
  • Code of Conduct
  • Contact

Confirm

  • Cancel
  • Confirm

Collect: undefined

Loading collection data...