Skip to content

Commit b25e4fc

Browse files
committed
"Loops Manipulations Moreover"
1 parent 8ae0d0f commit b25e4fc

4 files changed

+96
-1
lines changed

MultiDimentional Searching.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let groups = [
2+
["Martin", "Daniel", "Keith"],
3+
["Margot", "Marina", "Ali"],
4+
["Helen", "Jonah", "Sambikos"],
5+
];
6+
7+
8+
// We are looking for all the groups that have
9+
// two names starting with an M . If we find such a group, we will log it.
10+
11+
// for (let i = 0; i < groups.length; i++) {
12+
// let matches = 0;
13+
// for (let j = 0; j < groups[i].length; j++) {
14+
// if(groups[i][j].startsWith("M")){
15+
// matches++;
16+
// } else {
17+
// continue;
18+
// }
19+
// if (matches === 2){
20+
// console.log("Found a group with two names starting with an");
21+
// console.log(groups[i]);
22+
// break;
23+
// }
24+
// }
25+
// }
26+
27+
//Alternate Example :
28+
29+
for (let group of groups){
30+
for(let m_starts of group){
31+
// m_starts.toLowerCase
32+
if(m_starts.startsWith("M")){
33+
console.log(`Found Group name starts with M ${m_starts}`);
34+
break;
35+
}
36+
37+
}
38+
}

loops.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ for(let atr in garih){
106106
let arrried=["ahmed","ali","ansari"];
107107
arrried.forEach(element => {
108108
console.log(element);
109-
});
109+
});
110+
111+
let arrOfArrays = [];
112+
for (let i = 0; i < 3; i++){
113+
arrOfArrays.push([]);
114+
for (let j = 0; j < 7; j++) {
115+
arrOfArrays[i].push(j);
116+
}
117+
}
118+
console.table(arrOfArrays);

object and for loop.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//finding new car from array objects with matching desired properties.
2+
3+
let cars = [
4+
{
5+
model: "Golf",
6+
make: "Volkswagen",
7+
year: 1999,
8+
color: "black",
9+
},
10+
{
11+
model: "Picanto",
12+
make: "Kia",
13+
year: 2020,
14+
color: "red",
15+
},
16+
{
17+
model: "Peugeot",
18+
make: "208",
19+
year: 2021,
20+
color: "black",
21+
},
22+
{
23+
model: "Fiat",
24+
make: "Punto",
25+
year: 2020,
26+
color: "black",
27+
}
28+
];
29+
for (let i = 0; i < cars.length; i++) {
30+
if (cars[i].year >= 2020) {
31+
if (cars[i].color === "black") {
32+
console.log("I have found my new car:", cars[i]);
33+
break;
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let nr1 = 0;
2+
let nr2 = 1;
3+
let temp;
4+
fibonacciArray = [];
5+
while (fibonacciArray.length < 25) {
6+
fibonacciArray.push(nr1);
7+
temp = nr1 + nr2;
8+
nr1 = nr2;
9+
nr2 = temp;
10+
11+
}
12+
console.log(fibonacciArray);

0 commit comments

Comments
 (0)