WEB DEV CODE NOTES :

@VIDEO - 63 (#JS , INDEX.JS)


let arr = [1 ,2 ,3 ,4 ,5 ]
index   0 ,1 ,2 ,3 ,4
arr[0] = 5666;
console.log(arr)
console.log(arr.length)
console.log(arr, typeof arr)
console.log(arr.length)
console.log(arr[0])
console.log(arr[2])
console.log(arr[4])

console.log(arr.toString())
console.log(arr.join(" and "))
console.log(arr.pop()) //ye last wale element ko bahar  #nikal leta hai
console.log(arr.push(100)) // ye last me element ko @add kar deta hai

Notes: Or ye jo pop , push hai ye array ki length return karta hai....
Notes: "pop" ye "shift" ka #Bhai or "push" ye "unshift" ka #Bhai hota hai ....

console.log(arr.shift())  //ye first wale element ko bahar #nikal leta hai
console.log(arr.unshift(12)) // ye first me element ko @add kar deta hai
console.log(arr)

let a1 = [1, 2, 3]
let a2 = [4, 5, 6]
let a3 = [7, 8, 9]
console.log(a1.concat(a2,a3)) // ye return karega ek new array ye existing array ko #change nahi karega @new array [1, 2, 3, 4, 5, 6, 7, 8, 9]

let p = [5,2,4,9,6,1,3,8,7]
console.log(p.sort())

let numbers = [1,2,3,4,5,6]
    index   0,1,2,3,4,5
console.log(numbers.splice(1,3))// ye index 1 se 3 tak ke items ko remove ka dega
console.log(numbers.splice(1,3,222,333))// ye index 1 se 3 tak ke items ko remove ka dega or 222 , 333 ko add kar dega
console.log(numbers.slice(2))//[3,4,5,6]
console.log(numbers.slice(2,4))//[3,4]
console.log(numbers)

@VIDEO - 63 (#JS , MRF.JS)

let arr = [1, 13, 5, 7, 11];

let newarr = []
for (let index = 0; index < arr.length; index++) {
    const element = arr[index];
    newarr.push(element**2)
}

// Notes: (e=>is me single argument dena hota hai to bracket dene ki jarurat nahi padti ...
// Notes: Agar kisi "string" ko array banana hai to use #array.from("string") ...
let newarr = arr.map((e, index ,array)=>{
    return e**2
})

// console.log(newarr)
const greaterThanSeven = (e)=>{
    if(e>7){
        return true
    }
    return false
}
console.log(arr.filter(greaterThanSeven))

let arr2 = [1,2,3,4,5]

const red = (a ,b)=>{
        return a*b
}
console.log(arr2.reduce(red)) //By using this you can find #Fattorial of any @array ...


// Array.from("Shivam")


@VIDEO - 63 (#JS , LOOPS.JS)

let a = [1 , 93 , 5 , 6 , 88]

for (let index = 0; index < a.length; index++) {
    const element = a[index];
    console.log(element)
}

a.forEach((value, index, arr)=>{
    console.log(value , index ,arr)
})
used for objects
let obj = {
    a: 1,
    b: 2,
    c: 3
}
for (const key in obj) {
    if (Object.hasOwnProperty.call(obj, key)) {
        const element = obj[key];
        console.log(key ,element)
    }
}
for (const value of a) {
    console.log(value)
}

@VIDEO - 65 (#JS , NEW.JS) (calculating factorial using #Reduce & #for-loop)

let a = 6

// Factorial using reduce
function factorial(number){
    let arr = Array.from(Array(number+1).keys())
    let c = arr.slice(1,).reduce((a ,b)=>{ //Shortcut:((a, b)=> a*b)
        return a*b
    })
    return c
}

// Factorial using for loop
function facfor(number){
    let fac = 1;
    for (let index = 1; index <= number; index++) {
        fac = fac * index
    }
    return fac
}


console.log(factorial(a))
console.log(facfor(a))

/*Explanation:
...let a = 6;
function factorial(number) {
    let arr = Array.from(Array(number).keys());
    console.log(arr);
}
factorial(a);....


let a = 6;

This line creates a variable a and assigns the value 6 to it.
So, a is now equal to 6.

function factorial(number) { ... }
This defines a function called factorial which takes one argument (input) called number.
A function is like a block of code that does something specific, and in this case, it will calculate the factorial.

let arr = Array.from(Array(number).keys());
This line may seem tricky at first. Let's break it down:

Array(number): This creates an array with number empty slots. In your case, number is 6 (because a = 6), so it creates an array with 6 empty spots: [ , , , , , ].

.keys(): This method returns an iterator that contains the keys (indexes) of the array. For an array of 6 elements, the keys would be [0, 1, 2, 3, 4, 5]. These are the index numbers of the empty slots.

Array.from(): This method creates a new array from an array-like or iterable object. In this case, it converts the keys (the index numbers) into an actual array. So now arr will be [0, 1, 2, 3, 4, 5].

console.log(arr);
This prints the value of arr to the console (a tool in your browser that helps you see what's happening in your code).
When the function runs, it will print: [0, 1, 2, 3, 4, 5].

factorial(a);
This calls the factorial function and passes a (which is 6) as the number argument.
So, when this runs, the array [0, 1, 2, 3, 4, 5] will be printed in the console.
*/


















Comments

Popular posts from this blog

SIGMA WEB DEV JAVASCRIPT CLASS NOTES: