REST API: Country Codes
Given a country name and a phone number, query the API at
https://jsonmock.hackerrank.com/api/countries?name=country to get the country's
calling codes. Prepend the calling code to the phone number and return the string. If the data
array is empty, return the string '-1'. If there are multiple calling codes, use the one at the
highest index. The format of the number should be:
<Calling Code><space><Phone Number>
Example:
+1 7653555443
The response is a JSON object with 5 fields. The essential field is data:
In the data array, the country has the following schema:
page, per_page, total, total_pages, etc. are not required for this task.
If the country is found, the data array contains exactly 1 element. If not, it is empty and the function should return '-1'.
Complete the getPhoneNumbers function in the editor.
getPhoneNumbers has the following parameters:
- string country: the country to query
- string phoneNumber: the phone number
Returns
string: the completed phone number or -1
1Example 1
https://jsonmock.hackerrank.com/api/countries?name=Afghanistan.
The calling codes array contains 1 entry, '93'.2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.