//TS //TDD
enum Map { X1 = 100.0, X2 = 200.0, X3 = 250.0, X4 = 300.0, } const grannyFriends = [ ['A1', 'X1'], ['A2', 'X2'], ['A3', 'X3'], ['A4', 'X4'], ]; export default (friends: string[]): number => { return friends .map(f => { for (const gf of grannyFriends) { if (gf.includes(f)) { return Map[gf[1]]; } } return 0; }) .reduce((acc, curr) => (curr > 0 ? acc + (curr - acc) : acc), 0); };
TEST
import grannyTrip from './help-your-granny'; describe('tdd granny trip', () => { test('should calculate distances', () => { expect(grannyTrip(['A1', 'A2', 'A3', 'A4', 'A5'])).toEqual(300); expect(grannyTrip(['A1', 'A2', 'A3'])).toEqual(250); expect(grannyTrip(['A1', 'A2', 'A4'])).toEqual(300); }); });
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
//TS
//TDD
TEST