about | help | code help+videos | done | prefs |
Write a method that parses a list of directions and distances, returning a string that represents your net displacement from your starting position. The input parameter 'dirList' will contain a string of characters in the repeated form of "LN, " where L represents a letter N, S, E, or W indicating the direction of travel and N represents a single-digit number indicating how far you are traveling in that direction. Each time "LN" is followed by ", " EXCEPT for the last one. So "N3, S1, E5, E2, W1" represents going North 3 units, then South 1 unit, then East 5 units, then another 2 units, then going West 1 unit. This would place you 2 units North of your starting position and 6 units East of your starting position, so you return "N2 E6". Note: If your final displacement in the North-South direction is zero, report that as N0. If your final displacement in the East-West direction is zero, report that as E0. Look at the test data for further examples. Note that 'dirList' will contain at least one direction and amount. finalExam2014ParseDirections("W2, W7, W9, W9, W9, W1, W3") → "N0 W40" finalExam2014ParseDirections("N9, E2, S3, S1") → "N5 E2" finalExam2014ParseDirections("E4, E7, N2") → "N2 E11" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy