/*******************************************************************************
* Problem 6: format any number of coordinates as a list in a string
*
* You are asked to format geographic lat, lng coordinates in a list using your
* normalizeCoord() function from problem 5.
*
* Where normalizeCoord() takes a single geographic coord, the formatCoords()
* function takes a list of any number of geographic coordinates (strings),
* parses them, filters out any invalid coords, and creates a list (string).
*
* For example: given the following coords, “43.7955 -79.3496” and “[-62.1234,43.7955]”,
* a new list would be created of the following form “((43.7955, -79.3496) (43.7955, -62.1234))”.
*
* Notice how the list has been enclosed in an extra set of (…) braces, and each
* formatted geographic coordinate is separated by a space.
*
* The formatCoords() function can take any number of arguments, but they must all
* be strings. If any of the values can’t be parsed by normalizeCoord() (i.e., if
* an Error is thrown), skip the value. For example:
*
* formatCoords(“43.7955, -79.3496”, “[-62.1234,43.7955]”, “300, -9000”) should return
* “((43.7955, -79.3496) (43.7955, -62.1234))” and skip the invalid coordinate.
*
* @param {string} values – any number of string arguments can be passed
* @returns {string}
******************************************************************************/
function formatCoords(…values) {
// Replace this comment with your code…
}
problem test 6
const { formatCoords } = require(‘./solutions’);
describe(‘Problem 6 – formatCoords()’, function () {
test(‘valid lat, lng coord should be formatted correctly in a list’, function () {
let result = formatCoords(‘43.7955 -79.3496’);
expect(result).toBe(‘((43.7955, -79.3496))’);
});
test(‘multiple valid lat, lng coords should be formatted correctly in a list’, function () {
let result = formatCoords(‘43.7955 -79.3496’, ‘43.7955 -79.3496’);
expect(result).toBe(‘((43.7955, -79.3496) (43.7955, -79.3496))’);
});
test(‘multiple valid lat, lng coord formats should be formatted correctly in a list’, function () {
let result = formatCoords(‘43.7955 -79.3496’, ‘[-79.3496,43.7955]’);
expect(result).toBe(‘((43.7955, -79.3496) (43.7955, -79.3496))’);
});
test(‘invalid coords are skipped’, function () {
let result = formatCoords(‘43.7955 -79.3496’, ‘9000 9000’, ‘[-79.3496,43.7955]’);
expect(result).toBe(‘((43.7955, -79.3496) (43.7955, -79.3496))’);
});
test(‘if all values are invalid, an empty list is returned’, function () {
let result = formatCoords(‘90.01 -79.3496′, ’90 -181’);
expect(result).toBe(‘()’);
});
});