Homework Time //* Practice questions for map: //? 1: Given an array of strings representing names, create a new array that contains the uppercase version of each name. //? 2: Given an array of numbers, create a new array that contains the square of each number. //* Practice questions for filter: //? 1: Given an array of strings, create a new array that contains only the strings with a length greater than 4. //* const names: string[] = ["Alice", "Bob", "Anna", "Andrew", "Alex"]; //? 2: Given an array of strings, filter out the names that start with the letter "A". //! Homework 🧑💻 //? 1: Create a function called calculateAverage that takes an array of numbers as a parameter and returns the average of those numbers. //? 2: Write a function called findMaxValue that takes an array of numbers as a parameter and returns the maximum value in the array.
thankyou so much it was way more helpful for me as I was stuck... love from Pakistan ❤
@sagarmehta225
Жыл бұрын
practice is going really good maja aa raha hai 😀😅
@jagdishjena9058
11 ай бұрын
Thank you so much sir
@vikashanand2190
Ай бұрын
Awesome!
@muhammadsameer9161
5 ай бұрын
Answers: //* Practice questions for map: //? 1: Given an array of strings representing names, create a new array that contains the uppercase version of each name. let stringArray:string[] = ["Alice", "Bob", "Anna", "Andrew", "Alex"]; let uppercaseArray = stringArray.map((name) => name.toUpperCase()); console.log(uppercaseArray); //? 2: Given an array of numbers, create a new array that contains the square of each number. let numbersArray:number[] = [1, 2, 3, 4, 5]; let squaredNumbers = numbersArray.map((number) => number * number); console.log(squaredNumbers); //* Practice questions for filter: //? 1: Given an array of strings, create a new array that contains only the strings with a length greater than 4. const names: string[] = ["Alice", "Bob", "Anna", "Andrew", "Alex"]; let filterNames = names.filter((name) => name.length > 4); console.log(filterNames); //? 2: Given an array of strings, filter out the names that start with the letter "A". const startWithA:string[] = stringArray.filter((name) => name.startsWith("A")); console.log(startWithA); // Question 1 var calculateAverage = (numbers:any)=>{ let average:number = 0; average += numbers.map((currentVal:number)=>{ currentVal/numbers.length; }) return average; } console.log(calculateAverage([2,21,4,1,5,72])); // Question 2 const findMaxValue = (numbers:any):number =>{ let maximumValue:number = 0 for(let i:number=0; i
Can you help with average of numbers code, I'm not able to write that.
@learningwithsahil-it3523
9 ай бұрын
find total average number : const calculateAvarage = (arr:number[], page=10) => { let avarageNum = arr.reduce((intialValue, currentValue) => { return intialValue + currentValue * page }, 0) console.log(avarageNum) } calculateAvarage([1,2,3,4,5,6,7,8,9,10,11])
@rishiraj2548
Жыл бұрын
🙏🙏
@SanjayKumar-pp9ox
2 ай бұрын
create new array that contains sqaure of each number Ans - const squareNumber =(value:Array)=>{ return value.map((item)=> item ** 2) } console.log(squareNumber([2,8,6,11,12]))
@stblog3846
Жыл бұрын
Thapa bhai next.js ka full course kab. Aayega one videos me
Previous question ka answer 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); Bhai errors h toda correct kr dijiye plz..
@ThapaTechnical
Жыл бұрын
But I am happy that u tried. Sure I will
@DEEPANSHU_NAG
Жыл бұрын
@@ThapaTechnical itna hi solve ho paya const names:string[]=["Ashish","bob","amit","Abhishek","Shivam"]; const name:string[]=names.map((currVal:string)=> names.length>=3 );
@ONLINEREVIEWWALA
3 ай бұрын
Bangalore people use Nandini milk 😄
@ashishkumar-jo7cj
Ай бұрын
Nandni ye to aprachit waali to nhi khi 😅
@subhomoypal7982
Жыл бұрын
//? 1: Given an array of strings representing names, create a new array that contains the uppercase version of each name. let nameNewCollection: string[] = ["Subhomoy", "Arpita", "Debabrita"]; let newArray: string[] = nameNewCollection.map((elm) => elm.toUpperCase()); console.log(newArray); //? 2: Given an array of numbers, create a new array that contains the square of each number. let newNumberCollection: number[] = [1, 2, 3, 4, 5]; let newNumberArray: number[] = newNumberCollection.map((elm: number) => Math.pow(elm, 2)); console.log(newNumberArray); //* Practice questions for filter: //? 1: Given an array of strings, create a new array that contains only the strings with a length greater than 4. const names: string[] = ["Alice", "Bob", "Anna", "Andrew", "Alex"]; let newNames: string[] = names.filter((elm: string) => elm.length > 4); console.log(newNames); //? 2: Given an array of strings, filter out the names that start with the letter "A". const names: string[] = ["Alice", "Bob", "Anna", "Andrew", "Alex"]; let startNameWithA: string[] = names.filter((elm) => elm.indexOf("A") === 0); console.log(startNameWithA); // average let collection: number[] = [1, 2, 3, 4, 5]; let calculateAverage = (prem: number[]): number => prem.reduce((store, elm) => store + elm) / prem.length; console.log(calculateAverage(collection)); // max number let collection: number[] = [1, 2, 3, 4, 55, 3, 45]; function findMaxValue(array: number[]) { let maxValue: number = -Infinity; for (let item of array) { if (item > maxValue) { maxValue = item; } } console.log(maxValue); } findMaxValue(collection);
Пікірлер: 42