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. )

  • 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
    }

  • Custom User Avatar

    Check out ternary operators :)

  • 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