#8: TypeScript Function Mastery: Understanding Invocation, Declaration, and Return Types in Hindi

Поделиться
HTML-код
  • Опубликовано: 23 авг 2024

Комментарии • 63

  • @ThapaTechnical
    @ThapaTechnical  Год назад +5

    //! Homework for you Guys.. 🧑‍💻
    Q 1: Create a function called calculateAverage that takes an array of numbers as a parameter and returns the average of those numbers.
    Q 2: Write a function called findMaxValue that takes an array of numbers as a parameter and returns the maximum value in the array.

    • @DEEPANSHU_NAG
      @DEEPANSHU_NAG Год назад +2

      Ans 1:
      let arr:number =[8,2,9,7,4,6];
      const calculateAverage =(array[]:number):number => {
      let avg = array.reduce((accum,currVal,index,array)=>{
      let total = accum+=currVal;
      if(index === array.length-1)
      {
      return total/array.length;
      }
      return total;
      })
      }
      console.log(calculateAverage (arr));
      ---------------x---------------
      Ans 2:
      let arr:number =[8,2,9,7,4,6];
      const findMaxValue = (array[]: number):number => {
      let Max = array.reduce((a:number, b:number) => a > b ? a : b);
      }
      let Max = findMaxValue(arr);
      console.log(Max);

    • @codmukyt8506
      @codmukyt8506 11 месяцев назад

      Ans1:
      const calculateAverage = (arr: number[]): string => {
      const result = arr.reduce((currnetValue, accumulator) => {
      return currnetValue + accumulator;
      }, 0);
      return `Average is ${result / arr.length}`;
      };
      console.log(calculateAverage([1, 2, 3, 4, 5]));
      Ans2:
      const findMaxValue = (arr: number[]): string => {
      let maxNum = 0;
      for (let i = 0; i < arr.length; i++) {
      for (let j = 0; j < arr.length; j++) {
      if (arr[j] > arr[i]) {
      maxNum = arr[j];
      }
      }
      }
      return `Maximum Number is ${maxNum}`;
      };
      console.log(findMaxValue([1, 12, 6, 4, 5, 10]));

    • @shashwat_chovatiya
      @shashwat_chovatiya 4 месяца назад

      // Task 1
      const claculateAverage=(num:number[])=>{
      if (num.length === 0 ) {
      console.log("Array is empty");
      return 0;
      }
      const sum = num.reduce((acc,curr)=>acc + curr,0)
      const average = sum/num.length
      return average;
      }
      const array:number[] = [78,6,66,34,45,3,32,2]
      const averageResult = claculateAverage(array)
      console.log("Averege : " + averageResult);
      /*********************************************************/
      // Task 2
      const FindMaxNumber = (arr:number[]):number=>{
      if(arr.length=== 0 ){
      return 0;
      }
      else{

      let max:number = arr[0] ;
      for (let i = 0; i < arr.length; i++) {
      if (arr[i] >max) {
      max = arr[i];
      }
      }

      return max;
      }
      }
      const array1:number[] = [4,5,6,677,654,234,897]
      let maxNumber:number = FindMaxNumber(array1)
      console.log("maximum number " + maxNumber);

  • @Daily_dose_motivation29
    @Daily_dose_motivation29 Год назад +9

    Itna op content ha fir bhi itne kam views hai abhi tak shuru me itne jyada the shuru shuru me sabko josh chada rehta isliye sab dekhte dhere dhere utarjata hai isliye itna Kam views aara # best content on yt of typescript ❤❤

    • @ThapaTechnical
      @ThapaTechnical  Год назад +5

      Thank You so much :) I knw But kya kr sakte hai.. Tum ney comment ki, I am happy

    • @webdevankit4285
      @webdevankit4285 11 месяцев назад

      ​@@ThapaTechnical lovee uuu thapan bhai..you are gem❤ .

  • @pankajsharma-rf1ov
    @pankajsharma-rf1ov 2 месяца назад

    I started my react journey by watching your videos and now i am on the way of ts. i am enjoying by watching and implementing side by side. Thanks for this all 🙏❤

  • @namanmamodia8056
    @namanmamodia8056 Год назад +2

    // Function calculateAverage which accepts array of numbers in argument is:
    Typescript code
    const calculateAverage = (myarr: number[]) => {
    const sum = myarr.reduce((accumulator: number, currentVal: number) => accumulator + currentVal);
    return sum/(myarr.length)
    }
    const average = calculateAverage([6, 8, 11, 10, 15, 12]);
    console.log("Average of numbers :", average);
    After compilation javascript code
    var calculateAverage = function (myarr) {
    var sum = myarr.reduce(function (accumulator, currentVal) { return accumulator + currentVal; });
    return sum / (myarr.length);
    };
    var average = calculateAverage([6, 8, 11, 10, 15, 12]);
    console.log("Average of numbers :", average);
    output : Average of numbers : 10.333333333333334

  • @PoojaGupta-pm8ok
    @PoojaGupta-pm8ok 5 месяцев назад

    its pretty basic but aaj pehli baar arguments and parameters ka diff pata chala.

  • @sohailmohammed4024
    @sohailmohammed4024 6 месяцев назад

    World best typescript course

  • @mahesh1989mah
    @mahesh1989mah 3 месяца назад

    Q 1: Create a function called calculateAverage that takes an array of numbers as a parameter and returns the average of those numbers.
    function calculateAverage(numbers: number[]): number {
    return numbers.reduce((acc, num) => acc + num, 0) / numbers.length;
    }
    // Example usage:
    const numbers: number[] = [10, 20, 30, 40, 50, 60];
    const average: number = calculateAverage(numbers);
    console.log("Average:", average);

  • @munmun4022
    @munmun4022 Год назад

    Backend with typescript full tutorial needed

  • @user-cs3vk4kf4y
    @user-cs3vk4kf4y 9 месяцев назад +1

    ---Calculate Average:
    const calculateAverage = (array:number[]):number=>{
    let sum = array.reduce((acc,num)=>acc+num)
    return sum/array.length;
    }
    console.log(calculateAverage([1,1,1,13]))
    ---Max Value:
    const fixedmaxvalue = (array:number[]):number=>{
    let maxValue = Math.max(...array)
    return maxValue
    }
    console.log(fixedmaxvalue([1,1,31,13]))

  • @subhomoypal7982
    @subhomoypal7982 Год назад

    I have seen your previous ts tutorial where I learn about array parameter
    let arr = [10, 20, 30, 40, 50];
    function findMaxValue(array: number[]) {
    let maxValue: number = -Infinity;
    for (let item of array) {
    if (item > maxValue) {
    maxValue = item;
    }
    }
    console.log(maxValue);
    }
    findMaxValue(arr)

  • @ballagtech7430
    @ballagtech7430 Год назад

    Q 1:
    const calculateAverage = (par:any):number=>{
    let sum = 0;
    for(let i = 0; i< par.length; i++){
    sum = sum+par[i]
    }
    return (sum/par.length)
    }
    let arr = [2,5,6,4,1,8,9]
    console.log(calculateAverage(arr))
    Q2:
    const findMaxValue = (par:any):number=>{
    let max = par[0]
    for(let i = 1; i max){
    max = par[i]
    }
    }
    return max;
    }
    let arr2 =[8,90,56,4,1,3,4,32]
    console.log(findMaxValue(arr2))

  • @mahesh1989mah
    @mahesh1989mah 3 месяца назад

    Q 2: Write a function called findMaxValue that takes an array of numbers as a parameter and returns the maximum value in the array.
    function findMaxValue(numbers: number[]): number {
    return Math.max(...numbers);
    }
    // Example usage:
    const numbers: number[] = [10, 20, 30, 40, 41];
    const maxValue: number = findMaxValue(numbers);
    console.log("Maximum Value:", maxValue);

  • @BillaSaheb786
    @BillaSaheb786 Год назад

    Awesome, nice, Excellent

  • @YashSingh-zf1bp
    @YashSingh-zf1bp Год назад

    awesome explation

  • @TheCricketerKid
    @TheCricketerKid Месяц назад

    Q 1: Create a function called calculateAverage that takes an array of numbers as a parameter and returns the average of those numbers.
    let arr:number[] = [5,10,15,20,25];
    let sum = 0;
    let average = 0;
    function calculateAverage():number{
    for(let temp of arr){
    sum = sum + temp;
    }
    average = sum / arr.length;
    return average;
    }
    console.log(calculateAverage());
    Q 2: Write a function called findMaxValue that takes an array of numbers as a parameter and returns the maximum value in the array.
    let arr:number[] = [5,10,25,20,65,55,4,95];
    let greater = 0;
    function findMaxValue():number{
    for(let temp of arr){
    if(temp > greater){
    greater = temp;
    }

    }

    return greater;
    }
    console.log(findMaxValue());

  • @shubhambhardwaj8894
    @shubhambhardwaj8894 Год назад

    Thank you for the best content 🙏

  • @Daily_dose_motivation29
    @Daily_dose_motivation29 Год назад

    Awesome ❤

  • @Kya_Documents_Chahiye
    @Kya_Documents_Chahiye Год назад

    Awesome content ❤Sir

  • @itzallabouttech3616
    @itzallabouttech3616 Год назад +1

    const calculateAverage = (array: unknown): unknown => {
    if (Array.isArray(array)) {
    if (array.every((a) => typeof a === "number")) {
    return array.reduce((a, b) => a + b) / array.length;
    } else {
    return "Enter only number contain arrays";
    }
    } else {
    return "The Argument is not an Array";
    }
    };
    const findMaxValue = (array: any): unknown => {
    const maxNum = Math.max(...array);
    return maxNum;
    };
    Hey brother i have a question that what we write if we want argument must be array i try array and object keyword but it don't work then I use any and unknown

    • @priyobrotokar
      @priyobrotokar Год назад

      u can use type number[ ] for number array arguments.

  • @ilyazzz_31
    @ilyazzz_31 11 месяцев назад

    function findAvg(arr: number[]): number {
    let max: number = arr[0];
    for (let i: number = 0; i < arr.length; i++) {
    if (arr[i] > max) {
    max = arr[i];
    }
    }
    return max;
    }
    console.log(findAvg(numbers));

  • @BeHappy-lh4ug
    @BeHappy-lh4ug 3 месяца назад

    amazing

  • @Daily_dose_motivation29
    @Daily_dose_motivation29 Год назад +1

    Sir ek confusion hai ki ye function jo hw wala hai vo argument me array of no's lega toh parameter me kaise array type define karenge kuki abhi array type nahi padhe?

  • @nawaz8682
    @nawaz8682 Год назад

    function calculateAverage(args: number[]): number {
    let abcd = args.reduce((acc, val) => acc + val);
    return abcd / args.length;
    }
    console.log(calculateAverage([10, 20, 30, 40]));

  • @chetangupta2130
    @chetangupta2130 Год назад

    // 1. create a function called calculateAverage that takes an array of number as a parameter and returns the average of those numbers.
    function calculateAverage(numbers: number[]): number {
    const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue);
    const average = sum / numbers.length;
    return average;
    }
    const numbersArray = [1, 2, 3, 4, 5];
    const averageResult = calculateAverage(numbersArray);
    console.log(averageResult); // Output: 3
    // 2. write a function called findMaxValue that takes an array of number as a paramenter and returns the maximum value in the array.
    function findMaxValue(numbers: number[]): number {
    numbers.sort()
    return numbers[numbers.length-1]
    }
    const numberArray = [8,2,9,7,4,6];
    const maxval = findMaxValue(numberArray);
    console.log(maxval); // Output: 9

    • @sagarmehta225
      @sagarmehta225 Год назад +1

      try the 2nd question taking big numbers as arguments above 100 and 1000 and you will learn a new thing for sure and then let me know

  • @rishiraj2548
    @rishiraj2548 2 месяца назад

    17:07 What is WebStorm?

  • @CodeChaos-jd2be
    @CodeChaos-jd2be 8 месяцев назад

    Average Question:
    const a:number[]=[12,4,32,34,67,56];
    const AvgNumber =(x:number[]):number=>{
    let sum:number = 0;
    x.map((a)=>{
    sum=sum+a;
    })
    return( sum/(x.length) )
    }
    console.log(AvgNumber(a));
    Highest Number:
    const a:number[]=[12,4,32,-89,34,67,56]
    function GreateNumber(x:number[]):number{
    var lar:number=0;
    x.map((a)=>{
    if(a>lar){
    lar=a;
    }
    })
    return lar;
    }
    console.log(GreateNumber(a));

  • @satyam_code
    @satyam_code 19 дней назад

    💙💙

  • @rishiraj2548
    @rishiraj2548 Год назад

    Good day greetings

  • @CosMIcAkaSh1111
    @CosMIcAkaSh1111 10 дней назад

    // ? creating a function which takes an array and give us the average number
    // const average = (arr: any) =>{
    // let avg = arr.reduce((accu : number, elem : number) =>{
    // return accu + elem / arr.length
    // },0)
    // return avg
    // }
    // console.log(average([1,2,3,4,5]))
    // ! make a function which takes an array and gives us the maximum number
    const maxNum = (arr :any) :number =>{
    let max = arr.reduce((accu: number, elem: number) =>{
    // return accu > elem ? accu : elem
    return Math.max(accu, elem)
    },0)
    return max
    }
    console.log(maxNum([1,2,3,48,97]))
    complete assignment

  • @CHETANRATHOD-eq1bx
    @CHETANRATHOD-eq1bx Год назад

    const avg=(arry:number[]):number=>{
    return arry.reduce((acc,curr)=>acc+curr)/arry.length
    }
    const q:number[]=[1,2,3,4,5]
    console.log(avg(q))
    const maxn=(maxx:number[]):number=>{
    return Math.max(...maxx)
    }
    const s:number[]=[1,2,3,4,5]
    console.log(maxn(s))

  • @rajkurane2507
    @rajkurane2507 Год назад

    const calculateaverage = (numbers: number[]):number => {
    const totalSum: number = numbers.reduce((num1, num2) => num1 + num2);
    const average: number = totalSum / numbers.length;
    return average;
    }
    console.log(calculateaverage([1,2,3]));

    • @itachiuchiha1029
      @itachiuchiha1029 8 месяцев назад

      you don't need to assign number to average cause the function itself is returning the number so only returning average will return the number type.
      hope it was helpful for you.

  • @rahulkar5256
    @rahulkar5256 Год назад

    Thapa vai apka react e-commerce website ko fetch nahi kar pa raha pls look into it ..

  • @abbasjan5395
    @abbasjan5395 Год назад

    videos are in reverse order, video number 1 is actually video number 8.

  • @HimanshuNanikwal
    @HimanshuNanikwal 3 месяца назад

    // ================Q7==================
    const calculateAverage = (no: number[]): number => {
    return no.reduce((sum, currentNo) => sum + currentNo, 0);
    };
    console.log("------------>calculateAverage", calculateAverage([5, 15, 20, 10]));
    // ================Q8==================
    const findMaxValue = (no: number[]): number => {
    return Math.max(...no);
    };
    console.log(
    "------------>findMaxValue",
    findMaxValue([10, 20, 30, 40, 50, 100])
    );

  • @abubakar-shaikh-dev
    @abubakar-shaikh-dev Год назад

    //Calculate Average
    const calcAvg = (nums:any):number =>nums.reduce((a:number,b:number)=>a+b)/nums.length
    console.log(calcAvg([2,3,3,5,7,10]))
    //Find Maximum Value
    const maxVal = (nums:unknown):number => nums.reduce((a:number,b:number)=>a>b?a:b)
    console.log(maxVal([2,11,3,5,7,10]))