@@ -3292,7 +3292,85 @@ function floyedCycleDetection(){
32923292 return false
32933293}
32943294=======================================================================================================================================================================
3295+ This: This is a keyword from where it gets belongs to. This is a current object. In javascript, this behave in diff manner, it depends in the env where it's getting
3296+ invoked. (https://www.youtube.com/watch?v=wp-NEcAck1k&t=427s)
32953297
3298+ In IIFE : this is pointing to Window
3299+ In object : if normal function then pointing to block scope. if arrow function pointing to window.
3300+ In function constructor : pointing to function
3301+ If we didn't invoked properly(without paranthesis) then it will give undefined.
3302+ =======================================================================================================================================================================
3303+ function curryingWithRecursion(a){
3304+ return function(b) {
3305+ return b ? curryingWithRecursion(a+b) : a
3306+ }
3307+ }
3308+ console.log(curryingWithRecursion(1)(2)(3)(4)(5)()) //always use at last empty parenthesis
3309+ ======================================================================================================================================================================
3310+ How can you optimise the multiple of times API calls - using debaouncing, we can restrict the function calls ..
3311+ Check code implementation:
3312+ function debounce(func, a){
3313+ let timer;
3314+ return ()=>{
3315+ clearTimeout(timer);
3316+ timer = setTimeout(()=>{
3317+ func();
3318+ }, a)
3319+ }
3320+ }
3321+ const printName = () => {
3322+ console.log("Priya");
3323+ }
3324+
3325+ debounce(printName(), 8000)()
3326+ ======================================================================================================================================================================
3327+
3328+ function maxSumSubArray(arr){
3329+ let max = 0;
3330+ for(let i=0; i<arr.length; i++){
3331+ let currMax = 0;
3332+ for(let j=i; j<arr.length; j++){
3333+ currMax += arr[j]
3334+ if(currMax > max){ //or max = Math.max(max, currMax)
3335+ max = currMax
3336+ }
3337+ }
3338+ }
3339+ return max
3340+ }
3341+
3342+ console.log(maxSumSubArray([1,2,-1,3,-2]))
3343+ ======================================================================================================================================================================
3344+ function hello(){
3345+ for(var i=0; i<=3; i++){
3346+ setTimeout(()=>{
3347+ console.log(i)
3348+ }, 1000)
3349+ }
3350+ }
3351+ hello() //4 4 4 4
3352+
3353+ function hello(){
3354+ for(let i=0; i<=3; i++){ //using let getting new refrences
3355+ setTimeout(()=>{
3356+ console.log(i)
3357+ }, 1000)
3358+ }
3359+ }
3360+ hello() //0 1 2 3
3361+
3362+ function hello(){
3363+ for(let i=0; i<=3; i++){ //alternative of let i.e closures and passing indexes
3364+ function hi(i){
3365+ setTimeout(()=>{
3366+ console.log(i)
3367+ }, 1000)
3368+ }
3369+ hi(i)
3370+ }
3371+ }
3372+ hello() //0 1 2 3
3373+ =========================================================================================================================================================================
32963374
32973375
32983376
0 commit comments