Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,51 @@ const getCountryDetailsByCapital = (capital) => {
return getCountriesByObject(capital, "capital");
};

/**
* @param {string} language_code The name (not case-sensitive) of the language_codes of the country
* @returns {Array} An array of country objects
*/
const getCountryDetailsBylanguageCodes = (language_code) => {
let resultArray = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@majidtaherkhani

Suggested change
let resultArray = [];
return data.filter(item => item["language_codes"].includes(language_code))

data.forEach((item) => {
if(item["language_codes"].includes(language_code)){
resultArray.push(item);
}
});
return resultArray;

};

/**
* @param {integer} size The name (not case-sensitive) of the size of the country
* @returns {Array} An array of country objects
*/
const getCountryDetailsBySizeRangeKm = (size) => {
let resultArray = [];
data.forEach((item) => {
if(Math.abs(item.area.km2-size)<100){
resultArray.push(item);
}
});
return resultArray;

};

/**
* @param {integer} size The name (not case-sensitive) of the size of the country
* @returns {Array} An array of country objects
*/
const getCountryDetailsBySizeRangeMi = (size) => {
let resultArray = [];
data.forEach((item) => {
if(Math.abs(item.area.mi2-size)<100){
resultArray.push(item);
}
});
return resultArray;

};

/**
* Returns an array of objects, each containing `country`, `capital`,
* `currency` and `native_language` filtered by `country` .
Expand Down Expand Up @@ -231,6 +276,17 @@ const getCountriesByConstitutionalForm = (constitutionalFormName) => {
return result;
}

/**
* Returns an array of objects, each containing `country`, `capital`,
* `currency` and `native_language` filtered by `country` .
* @param {string} phone_code The name (not case-sensitive) of the country
* @returns {Array} An array of country objects
*/
const getCountryDetailsByPhoneCode = (phone_code) => {
return getCountriesByObject(phone_code, "phone_code");
};


/**
* Returns an array of objects containing all countries, each containing `country`, `capital`,
* `currency`, `native_language`, `famous_for`, `phone_code`, `flag` and `drive_direction` filtered by `is_landlocked`
Expand Down Expand Up @@ -266,6 +322,7 @@ const getCountryNeighbors = (country) => {
return data.filter(({ neighbors }) => neighbors.includes(foundCountry.iso.alpha_2));
};


module.exports = {
getRandomCountry,
getNRandomCountriesData,
Expand All @@ -283,4 +340,9 @@ module.exports = {
getCountriesByConstitutionalForm,
getCountriesByLandLock,
getCountryNeighbors,
getCountryDetailsByPhoneCode,
getCountryDetailsBySizeRangeMi,
getCountryDetailsBySizeRangeKm,
getCountryDetailsBylanguageCodes,

};