-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparttwo.js
More file actions
59 lines (38 loc) · 1.35 KB
/
parttwo.js
File metadata and controls
59 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let arr=[2,3,5]
arr.forEach(function(Element,index,arr){
console.log(index,Element,arr)
})
//Arrow function
arr.forEach((Element,index,arr)=>{
console.log("arrow",index,Element,arr)
})
const heroes=["superman","batman","ironman","allah"]
heroes.forEach((el)=>{console.log(el.toUpperCase())})
//converts lowercase string to uppercase strings
//Using map
arr.map(function(index,element,arr){
console.log(index,element,arr)
})
//Doing everything using map
heroes.map((el)=>{console.log(el.toUpperCase())})
//now using filter
console.log(heroes)
const heroesWithMan=heroes.filter((hl)=>{
return hl.endsWith('man')//always use return statement with it
})
console.log(heroesWithMan)//returns only which have man in their last
//shopping cart
const cartBill=[20,30,50]
const sumOfCartBill=cartBill.reduce((prev,curr)=>prev+curr,0)
console.log(sumOfCartBill)
//check all value are numbers
const gameScore=[200,300,310,250,150]
const gameScoreCheck=gameScore.every((v)=>typeof v==="number")//writer number in lowercase otherwise answer will be false because datatype is number only.
console.log("check: ",gameScoreCheck)
//find score above 200
const scoreAbove200=gameScore.find((score)=>score>200)//output will be the first number which will come first in arrray and will be greater than 200.
console.log(scoreAbove200)
//to study
//findindex
//sort
//some