Lets jump right into an example:
In our code we’ve created a class Person. When creating a new person it takes in one parameter in the constructor ‘name’. In the class we have two functions ‘sayNameArrow’ and sayNameFunction. In ‘sayNameArrow’ we have a setTimeout with an anonymous arrow function that logs out ‘Arrow:’ and this.name immediately. In sayNameFunction we have the exact same code but instead of an anonymous arrow function we have a regular anonymous function and this logs ‘Function’ and this.name.
The only difference is whether or not the function was called with an arrow function or not…
Bubble sort is a sorting algorithm that can be use on relatively small data sets. In terms of big O notation, the best case scenario is O(n), in most cases however the run time will be O(n²). What bubble sort does is it compares every adjacent value to one another, if the current value is greater than the next value the two values swap positions. This continues on through multiple passes through the array until the larger values “bubble” to the end of the array.
To give a visual representation of this, lets say we have an array [3, 1…
What is currying?
In order to speak about currying we have to talk about functional programming. Function programming is becoming somewhat of a buzz word in terms of a paradigm shift in programming. What functional programming is, is the process of programming with pure functions, avoiding any side effects and shared state. Out of this paradigm concepts like currying are born. So what exactly is currying? Currying is a way in which we can transform a function that takes in multiple arguments into a series of partials. In other words a function which is usually called in this manner: f(a…
For this algorithm problem, it asks you, given an array of integers find the contiguous subarray which has the largest sum and return its sum.
array = [-2, 1, 3, -2, 1, 4, -5, 1]
sum = 7
explanation: [1, 3, -2, 1, 4] is the largest sub array within the given array which adds up to 7.
The naive solution to this problem would be to brute force it. This just means that starting with the element at the first index in the array, you would form all subarrays available, as you iterate through the array. …
The call stack in the most basic sense is a data structure that functions on a last in first out principal to temporarily store and manage functions when they are invoked(called). Another thing to keep in mind about the call stack is, it is single threaded. Being single threaded means it only processes one command at a time. In this case if our call stack contains more than one function invocation, the last function that was invoked would resolve first. A simple example of this is:
In this example…
An execution context can be defined as the environment in which your code…executes in…
To clarify there are only two instances in which an execution context is created:
We’ll circle back to this later.
An execution context has two phases a “creation” & “execution”. In the creation phase all variables are declared and a space is reserved for them in memory. In this phase variables are not yet assigned their given value. …
A callback is a function that is passed as an argument to another function.
what is a higher order function?
A higher order function is a function that takes at least one function as an input and/or returns a function as an output.
So…what does this mean and what is the purpose?
Lets look at some code first!
In our example here we have a function manipulate, it takes a parameter callback. …