-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (55 loc) · 1.58 KB
/
Copy pathapp.js
File metadata and controls
71 lines (55 loc) · 1.58 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
60
61
62
63
64
65
66
67
68
69
70
71
// Function #1: Array Slice;
const foods = ["pizza", "burger", "fingerChips", "donuts", "springRoll"]
const modifiedFood = foods.slice(
foods.indexOf("pizza") + 1,
foods.indexOf("springRoll")
)
console.log(modifiedFood)
//function #2: Array Spliceconst
var foods1 = ["pizza", "burger", "fingerChips", "donuts", "springRoll"]
var modifiedFood1 = foods1.splice(2, 0, "noodles", "icecream")
console.log(foods1)
//Function #3: Filter
const numberArray = [12, 324, 213, 4, 2, 3, 45, 4234]
const isEvan = (numberArray) => {
return numberArray.filter(function (number) {
if (number % 2 === 0) {
return number
}
})
}
var evenNumbers = isEvan(numberArray)
console.log(evenNumbers)
const isPrime = (numberArray) => {
return numberArray.filter((number) => {
for (var i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) return false
}
return true
})
}
var primeNumbers = isPrime(numberArray)
console.log(primeNumbers)
//Function #4: Reject
var reject = {}
//Function #5: Lambda function
var evenNumbers1 = numberArray.filter((number) => {
if (number % 2 == 0) return number
})
console.log(evenNumbers1)
//Function #6: Map
const myArray = [11, 34, 20, 5, 53, 16]
const findSquareOfNumbers = (myArray) => {
return myArray.map(function (number) {
return number * number
})
}
var SquareOfNumbers = findSquareOfNumbers(myArray)
console.log(SquareOfNumbers)
//Function #7: Reduce
const myArray1 = [2, 3, 5, 10]
const multiply = (myArray1) => {
return myArray1.reduce((a, b) => a * b, 1)
}
var multiplication = multiply(myArray1)
console.log(multiplication)