I am using this code to fetch 100 trending public repos on GitHub.
For every language, I calculated the The list of repos using the language, but I can't calculate the number of repos using this language
part of my code
const api_url =
"https://api.github.com/search/repositories?q=created:>30&sort=stars&order=desc&per_page=100";
const response = await fetch(api_url);
const data = await response.json();
var urls = data.items
.map((a) => ({
language: a.language,
url: a.url,
}))
.filter((el) => {
return el.language != null;
}),
result = urls.reduce((r, { language, url }) => {
match = r.find((item) => language in item);
match ? match[language].push(url) : r.push({ [language]: [url] });
return r;
}, []);
This is sample of my output
[{
"Vala": [
"https://api.github.com/repos/p-e-w/finalterm"
]},
{
"Swift": [
"https://api.github.com/repos/louisdh/panelkit",
"https://api.github.com/repos/hyperoslo/Whisper",
]},
{
"C": [
"https://api.github.com/repos/wishstudio/flinux",
"https://api.github.com/repos/Sunzxyong/Tiny"
]}]
My desired output is to count the URLs of each language and append it to its corresponding language
{ "Vala": [ "https://api.github.com/repos/p-e-w/finalterm" ], count: 1}? You could just go through each language and get the.lengthof the array.