• Is parseInt and parseFloat the same thing?

    Almost! Both take a string as input and return a number. But one returns an integer and the other a float. So parseInt("3.14") returns 3 and parseFloat("3.14") returns 3.14

  • I would like to talk more about first class functions / maybe going more in depth about functions

    Functions are very cool. We're all used to variables that contain unknown values:

    
        let x = prompt("enter your age", 18);
        let y = x + 1;
        alert("Next year, you will be "+y);
    
    

    (I made a mistake above; what is it?)

    In the above code, we know what all the functions are. But that might not be the case in another situation, where the variable holds a function.

    
        function doSomething(seq, fn) {
            return seq.map(fn);
        }
        function square(x) {
            return x*x;
        }
        console.log(doSomething([1,2,3], square));
        console.log(doSomething([1,2,3], x => x*x*x));
    
    

    For fun, here's the same idea in Python:

    
    def do_something(seq, fn):
        return [ fn(x) for x in seq ]
    
    def square(x):
        return x**2
    
    print(do_something(range(5), square))
    
    print(do_something(range(5), lambda x: x**3))
    
    
  • Could you explain anonymous functions more?

    When we are going to pass a function to someone else to run, often we don't need a name for it. So, we just give the code: an anonymous function.

    After all, the only reason to have a name is to refer to something later.

  • I would love to talk more about arrow functions, those seem very cool.

    Yeah, they are, aren't they? Very concise in some cases (see above). There are some subtle differences, which we'll talk about later. But essentially:

    
    function name(a, b) { return expr(a,b) ; }
    
    

    Is the same as

    
    (a, b) => expr(a,b)
    
    

    You omit the name, if any, the return keyword and the braces.

    But you can add the braces and return back if you need them.

  • more on forEach methods?

    forEach is a method on arrays that takes a function and invokes it for each element of the array. It returns no value. We can use it instead of a loop. (Loops also return no value.)

  • It would be helpful to go over the forEach() method and why it is preferred over loops.

    It's not necessarily preferred in industry, but for this class, I do. Because:

  • I would like to learn how to iterate and loop through functions in javascript like python and java, though I know this is something I need to explore more on my own/with peers.

    I'm not sure what you mean by "looping through functions". Do you mean the forEach method? We will do some practicing with that.

  • Can we talk more about sorting? I'm still a little confused about how comparison functions work.

    Sorting is similar to Python, but a little different. In Python:

    
    y = [1, 8, 4, 16, 25 ]
    
    print(sorted(y))
    print(sorted(y, key = lambda n: str(n)))
    print(sorted(y, key = lambda n: str(n), reverse = True))
    
    

    In JavaScript, we provide a comparison function between any two elements:

    
    var x = [3, 5, 7, 9, 11];
    var y = x.map(n => n*n);
    y.sort()
    y.sort( (a,b) => a-b )
    y.sort( (a,b) => b-a )
    
    

    The comparison function must return *negative* if a should precede b, otherwise *positive*, and *zero* for ties.

  • Everything's clear. Thank u :)

    Glad to hear it!