Rest api question

I have to make a call and return an array. Im not allowed to change whats in main. how can I get result to be userNamesArray and not undefined

const axios = require("axios");
const one = "https://jsonmock.hackerrank.com/api/article_users?page=1";
const two = "https://jsonmock.hackerrank.com/api/article_users?page=2";
async function getUsernames(threshold) {
  let userNamesArray = [];
  const requestOne = await axios.get(one);
  const requestTwo = await axios.get(two);
  axios.all([requestOne, requestTwo]).then(
    axios.spread((...responses) => {
      const responseOne = responses[0].data;
      const responseTwo = responses[1].data;
      userNamesArray = [
        ...makeUserArray(responseOne, threshold),
        ...makeUserArray(responseTwo, threshold),
      ];
      return userNamesArray;
    })
  );
}

function makeUserArray({ data }, threshold) {
  const filteredUsers = data.filter(
    (user) => Number(user["submission_count"]) > threshold
  );
  const newfilteredUsers = filteredUsers.map((user) => user.username);
  return newfilteredUsers;
}

async function main() {
  const result = await getUsernames(10);
  console.log(result);
}
main();

fixed it…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.