Ad
  • Custom User Avatar

    kata hint != kata suggestion (you can always provide suggestion on how to improve description

  • Default User Avatar

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

  • Default User Avatar

    so this is all explained by the basic premise of that you can call a function and get something back. no separate mode of operation is needed for that to happen, it's just the same thing done repeatedly.

    and having a function nested inside another doesn't mean you can call it, you can only call it if that function is returned, same as how you can't be aware of some integer unless that integer is returned

    def f():
        x = 5  # can't see this variable nor its value from the outside
        return 3  # this is made available to the caller
        
    def g():
        def h():  # can't see this variable nor its value from the outside
            return 2
        return 4  # this is made available to the caller
    
    # g returns 4, calling 4, 4() is gonna get you a type error,
    # and the function h isn't reachable
    # ( because the second call doesn't refer to an inner function, it is simply `f(x)`  with f being g() )
    g()()
    

    likewise, you can return any function you want, regardless of where it is defined:

    def f():
        return print
    
    f()("hello world")
    
  • Default User Avatar

    Almost.
    You're not passing arguments to an inner function. You're calling a function. (has nothing to do with where it's defined, you have a function, you call it)
    calling a function looks like this:

    f(x)
    

    you're doing this:

    f = func(1)
    g = f(2)
    h = g(3)
    print(h)
    

    func is a function. you call it. you give it 1. it gives you a value back. that value is a function. you assign the variable f to it.
    f is a funciton. you call it. you .........
    g is ...
    h isn't a function, and you're not trying to call it. you convert it to string and write that string to stdout

  • Custom User Avatar

    Note how this statement: let result = chained([f1,f2,f3])(0) can be broken down:

    let something = chained([f1,f2,f3]);
    let result = something(0);
    

    Now your task would be to write chained in such a way, that when it returns something, this thing can be called in the next line as something(0).

    Don't feel bad for not getting this. The concept of high-order functions is not a complex one, but at the same time not easy to grasp for people not familiar with it. The fact that a function can be passed as a parameter to another function, and that a function can return another function, is quite often mind-boggling for beginners.

    Just do some research on "high order functions", "function chaining", "function composition", or come to Codewars Discord for further help.

  • Default User Avatar

    You should probably be looking at the individual calls.

    a + b + c
    doesn't make + behave differently from here:
    a + b

    in both cases, + gets two values as input and produces an output.
    and, you can rewrite the first one to this:

    d = a + b
    d + c
    

    which you can also do with all the calls involved in this kata. there's only ever one call happening at a time, and there's no special behaviour.

  • Custom User Avatar

    A Function(args)(input) call is not valid syntax.

    If you mean syntax like this: chained([f1,f2,f3])(0), then it is a valid syntax.

  • Custom User Avatar

    Write a function which takes a list of strings and returns each line prepended by the correct number.

    The number of line starts at 1, each new line is adds 1 to that counter, read the description again and see the example there. What each element of the list contains doesn't matter at all.