https://hianna.tistory.com/407
const axios = require('axios');
async function getTotalGoals(team, year) {
try{
var ans = 0, totalPage = 1, t = 1;
while (t <= totalPage){
const res1 = await axios.get('https://jsonmock.hackerrank.com/api/football_matches/', {
params: {
year : year,
team1 : team,
page : t
}
});
totalPage = res1.data.total_pages;
for (var item of res1.data.data){
ans = ans + parseInt(item.team1goals);
}
t+=1;
}
t=1;
while (t <= totalPage){
const res2 = await axios.get('https://jsonmock.hackerrank.com/api/football_matches/', {
params: {
year : year,
team2 : team,
page : t
}
});
totalPage = res2.data.total_pages;
for (var item of res2.data.data){
ans = ans + parseInt(item.team2goals);
}
t+=1;
}
return ans;
} catch (error) {
console.error(error);
}
}
async function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const team = readLine();
const year = parseInt(readLine().trim(), 10);
const result = await getTotalGoals(team, year);
ws.write(result + '\n');
ws.end();
}
const axios = require('axios');
async function getWinnerTotalGoals(competition, year) {
try {
const getWinner = await axios.get('http://jsonmock.hackerrank.com/api/football_competitions/',{
params : {
name : competition,
year : year
}
});
const winner = getWinner.data.data[0].winner
//console.log(winner);
let t = 1, totalPage = 1, ans =0;
while (t <= totalPage){
const getContests1 = await axios.get('http://jsonmock.hackerrank.com/api/football_matches/', {
params : {
competition : competition,
year : year,
team1 : winner,
page : t
}
});
totalPage = getContests1.data.total_pages;
t+=1;
//console.log(getContests1.data.data);
for (let item of getContests1.data.data) {
//console.log(item);
ans += parseInt(item.team1goals);
}
}
//console.log(ans);
t = 1;
totalPage = 1;
while (t <= totalPage){
const getContests2 = await axios.get('http://jsonmock.hackerrank.com/api/football_matches/', {
params : {
competition : competition,
year : year,
team2 : winner,
page : t
}
});
totalPage = getContests2.data.total_pages;
t+=1;
//console.log(getContests2.data.data);
for (let item of getContests2.data.data) {
//console.log(item);
ans += parseInt(item.team2goals);
}
}
return ans;
} catch(error){
console.error(error);
}
}
const axios = require('axios');
async function getNumDraws(year) {
try {
var goal = 0, ans = 0;
while (goal <= 10) {
const matches1 = await axios.get('http://jsonmock.hackerrank.com/api/football_matches/', {
params : {
year : year,
team1goals : goal,
team2goals : goal
}
});
goal += 1;
//console.log(matches1.data.total);
ans += matches1.data.total;
}
return ans;
} catch(error){
console.error(error)
}
}
λ°μν
'κ°λ° > Spring' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
μ€νλ§ μΉ κ°λ° λ°©μ (static / MVC / API) (0) | 2022.03.03 |
---|---|
Spring νλ‘μ νΈ μμ± (Gradle) (0) | 2022.03.03 |
ZonedDateTime (UTC -> KST) (0) | 2022.02.23 |
Spring ν΅ν© ν μ€νΈ - JUnit5 (0) | 2022.02.21 |
GraphQL (spring) (0) | 2021.12.18 |