//! 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.
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);
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 ❤❤
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 🙏❤
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)
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);
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);
// Function to calculate the average of an array of numbers function calculateAverage(numbers: number[]): number { if (numbers.length === 0) { throw new Error("Array cannot be empty"); } const sum = numbers.reduce((total, num) => total + num, 0); return sum / numbers.length; } // Example usage const data: number[] = [10, 20, 30, 40, 50]; const average = calculateAverage(data); console.log(`The average is: ${average}`);
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?
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; }
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));
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
// 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
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.
// ? 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
let maxandminnumber = [10, 49, 500, 600, 400, 300, 534]; function max_min(numbers: number[]): { max: number; min: number } { const maxNumber = Math.max(...numbers); // Find max const minNumber = Math.min(...numbers); // Find min return { max: maxNumber, min: minNumber }; // Return both as an object } const result = max_min(maxandminnumber); console.log(`The max number is: ${result.max}`); console.log(`The min number is: ${result.min}`);
//! 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.
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);
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]));
// 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);
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 ❤❤
Thank You so much :) I knw But kya kr sakte hai.. Tum ney comment ki, I am happy
@@ThapaTechnical lovee uuu thapan bhai..you are gem❤ .
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 🙏❤
its pretty basic but aaj pehli baar arguments and parameters ka diff pata chala.
// 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
World best typescript course
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)
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);
Backend with typescript full tutorial needed
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);
17:07 What is WebStorm?
---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]))
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))
// Function to calculate the average of an array of numbers
function calculateAverage(numbers: number[]): number {
if (numbers.length === 0) {
throw new Error("Array cannot be empty");
}
const sum = numbers.reduce((total, num) => total + num, 0);
return sum / numbers.length;
}
// Example usage
const data: number[] = [10, 20, 30, 40, 50];
const average = calculateAverage(data);
console.log(`The average is: ${average}`);
Thank you for the best content 🙏
Glad you enjoy it!
Awesome, nice, Excellent
Awesome content ❤Sir
Awesome ❤
awesome explation
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?
string[]
@@succeedwithuttam2271 bhai number[] hoga na kuki array of no lera string nahi
@@succeedwithuttam2271 aur bhai sir ne abhi tak nahi padhaya isliye puchra
Sure I will make a video on it tomorrow.. Baat tho sahi kahi ki abhi tak nia prdaya
@@ThapaTechnical 💓💓😄
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());
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));
amazing
Thapa vai apka react e-commerce website ko fetch nahi kar pa raha pls look into it ..
Sure I will
function calculateAverage(args: number[]): number {
let abcd = args.reduce((acc, val) => acc + val);
return abcd / args.length;
}
console.log(calculateAverage([10, 20, 30, 40]));
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
u can use type number[ ] for number array arguments.
// 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
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
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]));
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.
Good day greetings
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))
Thank You
I have gotten the easy solution from you.
@@subhomoypal7982 thanks bro...its all about vinod sir teaching skills
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));
// ? 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
videos are in reverse order, video number 1 is actually video number 8.
let maxandminnumber = [10, 49, 500, 600, 400, 300, 534];
function max_min(numbers: number[]): { max: number; min: number } {
const maxNumber = Math.max(...numbers); // Find max
const minNumber = Math.min(...numbers); // Find min
return { max: maxNumber, min: minNumber }; // Return both as an object
}
const result = max_min(maxandminnumber);
console.log(`The max number is: ${result.max}`);
console.log(`The min number is: ${result.min}`);
💙💙
----------------------------------first question-------------------------------------------
const calculateAverage =(num:number[]):number=>{
let Added:number =0;
for(let i:number =0;i{
let max:number =0;
for(let i:number =0;i
// ================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])
);
//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]))