-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvery&Some-Method.js
More file actions
104 lines (71 loc) · 2.92 KB
/
Every&Some-Method.js
File metadata and controls
104 lines (71 loc) · 2.92 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//////////////////////////////////////////
// The every() and some() are two built-in array methods in
// JavaScript that allow you to check the elements of an array
// based on a given condition. Both methods take a callback
// function as an argument, which is applied to each element
// of the array.
// The every() method tests whether all elements in the array
// pass the condition specified by the provided callback
// function. It returns true if the callback function returns
// true for every element, and false if any element fails
// the condition.
// The some() method tests whether at least one element in the
// array passes the condition specified by the provided
// callback function. It returns true if the callback function
// returns true for at least one element, and false if no
// element passes the condition.
//////////////////////////////////////////
const peoples = ["ADITYA","IMMORTAL","ASHU","AHAM"]
const res1 = peoples.every((people) => people.length === 4)
const res2 = peoples.some(people => people.length < 5)
console.log(res1);
console.log(res2);
//-------------------------------------------------
const songs = [
{ name : "O Mere Dil Ke Chain", duration : 4.37},
{ name : "Dekha Ek Khwah-2", duration : 5.21},
{ name : "Neele Neele Ambar Par", duration : 5.20},
{ name : "Bheegi Bheegi Raaton Mein", duration : 3.54},
{ name : "Rimjhim Gire Sawan", duration : 3.15},
];
const everyRes = songs.every(song => song.duration > 3)
const someRes = songs.some(song => song.duration > 3)
console.log(everyRes);
console.log(someRes);
//--------------------------------------------------
// Task32✅
// REFACTOR -> USE EVERY & SOME HELPERS
let products = [
{ name: "Checkers", category: "Toys" },
{ name: "Harry Potter", category: "Books" },
{ name: "iPhone", category: "Electronics" },
{ name: "Learn PHP", category: "Books" },
];
// do all products have a category of Books ?
let allProductsbooks = products.every(
(product) => product.category === "Books"
);
// do any products have a category of Books ?
let anyProductsbooks = products.some(
(product) => product.category === "Books"
);
console.log(allProductsbooks);
console.log(anyProductsbooks);
// ---------------------------
// const peoples = ["huxn", "jordan", "alex"];
// const res = peoples.every((people) => people.length === 4);
// const res2 = peoples.some((people) => people.length < 3);
// console.log(res);
// console.log(res2);
// //////////////////////////////////////////
// const songs = [
// { name: "Lucky You", duration: 4.34 },
// { name: "Just Like You", duration: 3.23 },
// { name: "The Search", duration: 2.33 },
// { name: "Old Town Road", duration: 1.43 },
// { name: "The Box", duration: 5.23 },
// ];
// const everyRes = songs.every((song) => song.duration > 3);
// const someRes = songs.some((song) => song.duration > 3);
// console.log(everyRes);
// console.log(someRes);