How do I decipher this callback function

12 Views Asked by At

Below is the code snippet in question. In particular I'm confused by the line with the .map() method. I've never seen this shorthand syntax used with .map()or in any other context with callback functions. I can't find any resources on it. Is this JQuery? 'c' is not declared anywhere else in the code that I can find. is this the equivalent of let catIDs = response.data.map((category) => category.id); and if so how does 'it' know that c = category? Any help is appreciated. If it's not clear, I'm still early in my coding journey.

async function getCategoryIds() {
  // ask for 100 categories [most we can ask for], so we can pick random
  let response = await axios.get(`${BASE_API_URL}categories?count=100`);
  let catIds = response.data.map(c => c.id);
  return _.sampleSize(catIds, NUM_CATEGORIES);
}
let catIds = response.data.map(c => c.id);

For more context, It's used again throughout the script:

async function getCategory(catId) {
  let response = await axios.get(`${BASE_API_URL}category?id=${catId}`);
  let cat = response.data;
  let allClues = cat.clues;
  let randomClues = _.sampleSize(allClues, NUM_CLUES_PER_CAT);
  let clues = randomClues.map(c => ({
    question: c.question,
    answer: c.answer,
    showing: null,
  }));

  return { title: cat.title, clues };
}

I tried passing c into the console but not surprisingly it was undefined. Additionally I brushed up on callback function syntax and the .map() method with no luck.

0

There are 0 best solutions below