JS Challenge

Challenge #1

Question board

Given a list of cities with their distances, write a function named findNearestCity that returns the city with the shortest distance. The distance may be provided in kilometers (km) or meters (m). Convert all distances to meters before comparing them.

Examples

findNearestCity([
  { city: 'KL', distance: '10km' },
  { city: 'PJ', distance: '500m' },
  { city: 'Shah Alam', distance: '3km' }
]); // 'PJ'
findNearestCity([
  { city: 'KL', distance: '2km' },
  { city: 'Penang', distance: '500m' }
]); // 'Penang'

Answer board

Loading...

Result

Submit your JavaScript and click Run.