Question: Oracle GBU , Online Assessment (Recent REST API Questions) | REST API : City Weather Station | REST API : Best TV Shows in Genre | 2023
2
Entering edit mode

ADD COMMENTlink 16 months ago Delta 2.9k
7
Entering edit mode

async function weatherStation(keyword) {

  let url = `https://jsonmock.hackerrank.com/api/weather/search?name=${keyword}`;

  keyword = keyword.toLowerCase();

  let ans = [];

  let response = await fetch(url + `&page=1`);

  response = await response.json();

  let arr = response.data;

  //console.log(arr);

  for (let j = 0; j < arr.length; j++) {

    let obj = arr[j];

    let name = obj.name;

    name = name.toLowerCase();

    if (name.includes(keyword)) {

      ans.push(obj);

    }

  }

  let total_pages = response.total_pages;

  //console.log(total_pages);

  for (let i = 2; i <= total_pages; i++) {

    let resp = await fetch(url + `&page=${i}`);

    resp = await resp.json();

    arr = resp.data;

    //console.log(arr);

    for (let j = 0; j < arr.length; j++) {

      let obj = arr[j];

      let name = obj.name;

      name = name.toLowerCase();

      if (name.includes(keyword)) {

        ans.push(obj);

      }

    }

  }

  let res = [];

  for (let i = 0; i < ans.length; i++) {

    let a = String(ans[i].name);

    let b = String(ans[i].weather);

    let c = String(ans[i].status[0]);

    let d = String(ans[i].status[1]);

    let x = a + "," + b + "," + c + "," + d;

    res.push(x);

  }

  return res;

}

 

weatherStation("Adelaide").then((data) => {

  console.log(data);

});

Is it correct?

ADD COMMENTlink 16 months ago Jeevan Ankadala • 70
Entering edit mode
0

googd

 

ADD REPLYlink 9 months ago
guts
• 0
0
Entering edit mode

do they allow python also ?

ADD COMMENTlink 15 months ago unicornme707 • 20
Entering edit mode
0

good

 

ADD REPLYlink 14 months ago
amaresh
• 0

Login before adding your answer.

Similar Posts
Loading Similar Posts