-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.js
More file actions
26 lines (21 loc) · 859 Bytes
/
tempCodeRunnerFile.js
File metadata and controls
26 lines (21 loc) · 859 Bytes
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
//! ---------------------------------------------
//? ----------- Football team and score is given. find the wining team with highest goal ------------
//! ---------------------------------------------
const teams = [
{ team: "Team A", score: 2 },
{ team: "Team B", score: 5 },
{ team: "Team C", score: 3 },
];
function findWinningTeam(teams) {
if (teams.length === 0) return null;
let winingTeam = teams[0];
console.log(`${teams[0].team} is the initial winning team with ${teams[0].score} goals. ${JSON.stringify(teams[0])} `);
for (let i = 0; i < teams.length; i++) {
if (teams[i].score > winingTeam.score) {
winingTeam = teams[i];
}
}
return winingTeam;
}
const winner = findWinningTeam(teams);
console.log(`The winning team is ${winner.team} with ${winner.score} goals.`); // The winning team is Team B with 5 goals.