Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    For whole integer inputs, it will not round for obvious reasons. As for the latter, it is up to your own research.

  • Custom User Avatar

    i did format and mark as spoiler.

    i dont understand why, when any other condition will round to 2 decimal places, or what you mean by casting to string type only

  • Custom User Avatar

    Because 1 rounded to 2 decimal places is still 1. If you want to add .00 to it, you will have to resort to other methods and not just casting it to string type only

    Also, please mark your code as spoiler and use formatting when asking questions --> read this

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Please use appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.

    expected [ +0 ] to equal +0

    Your function returns an array of digits instead of a single number composed of those digits.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

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

  • Custom User Avatar

    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

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