Ad
  • Custom User Avatar

    Yes, absolutely.

    It may not be "Simple", but function composition certainly is "Fundamental".

    Look at it this way: "1243".split("").sort().join("") is also function composition, just with a different syntax.

    ( That could have been compose( join(""), sort(), split("") )( "1243" ). Mind that the arguments to compose are functions. )

  • Default User Avatar

    Thanks very much for your reply. I haven't read "eloquent Javascript", but it's on my "must-read" list. I'm still feeling my way around Javascript, but you're the 3rd or 4th person to mention "eloquent Javascript", so it's apparently a very useful source.

  • Custom User Avatar

    Did you read eloquent javascript? The main thing that I think would be confusing is scope and closures, so perhaps looking into those two topics would be helpful.

    function mainScope (args) { //main function
    var newfunction = function(){ //still has access to variables accessible in mainScope
    return args; //can manipulate args as expected
    };
    return args;
    }

    function secondaryScope (args) { //new function
    newFunction(); //would throw error
    }

  • Default User Avatar

    Should this be included in Fundamentals? Everyone has his own definition of "fundamentals" but, from my perspective as someone who has done only the Codecademy course in Javascript and a handful of katas, the 'fundamental' tag seems a bit misplaced here.

  • Custom User Avatar

    If one uses 'letorconst` or other ES6 features, the code will get longer due to the transformation by babel. That should get mentioned in the description.

  • Custom User Avatar

    Pls help I've done a character count elsewhere it shows 245, the test says 280? I also sneakily tried assigning strings to vars at one point, which brought the actual count down further, but in the test it went even higher! confused..

  • Custom User Avatar

    Check out ternary operators :)

  • Custom User Avatar

    Please add this information into description. It can be confusing.

  • Custom User Avatar

    Bravo Peter \m/

  • Default User Avatar

    is there a way to do this in fewer than 250 chars without using regex? My only exposure to JS is completing a Codecademy course and some level 8 and level 7 katas. Based on my limited experience, I instinctively reached for a 'switch' statement, but that puts me around 350 chars, even after smushing my code together as much as possible. I suspect that I'm missing a more elegant solution, but I don't know regular expressions.

  • Default User Avatar

    Thanks, Dean! I'll get the hang of this environment soon.

  • Default User Avatar

    You should post this in the discuss thread of the kata you are having trouble with. You will see discuss with some speech bubbles just below the katas title. I believe this is the kata you are talking about. function within a function
    There are lots of things you can do with functions in javascript. In Javascript functions are actually just a special type of object so they can be returned or even passed around.
    so a function that returns another function would look something like this

    function a(n){
      return function(){
        ///do something with the argument n
      }
    }
    
    var b = a(9)
    // then b is a function that does something with 9
    b()  // is the same as a(9)()
    

    I hope that helps. If you are still stuck or just want to learn more about functions in functions here are some things to research on Google

    • Javascript closures
    • Immediately Invoked Function Expressions(IIFE)
    • Javascript scope
  • Default User Avatar

    I'm trying to teach myself Javascript to prepare for an assessment test given by Full Stack. I took Codecademy's online "Javascript" course, which felt like a good place to start. Now I'm trying some CodeWar challenges. I started at level 8 as would anyone, and I've submitted a few katas (Isograms, Remove the Minimum, Grasshopper - Grade book), but now I'm stuck on one that looks like it should be straightforward - "A function within a function". I'm trying to solve this, and I hate to put up the white flag, but I feel like I've run out of ideas. My question is whether I can find the solution to this somewhere. I want to move on to other katas and to continue learning, but I hate the feeling of moving past something without understanding it. Can someone offer any guidance on this?