about | help | code help+videos | done | prefs |
Write a method that returns the "place value sum" of the digits of a number. Be careful! This is tricky! Preconditions: 'num' will contain a non-negative number. The array 'values' will contain the place-values to apply. This array will have index zero be the least-significant place value, followed by index one being the next least-significant place value, etc. The array may have the same number of elements as the number of digits in 'num' or it may have more elements than that. Return the "place value sum". Here is an example: If 'num' is 246, and 'values' is {1,3,10,5}, the "place value sum" would be calculated this way: 6*1+4*3+2*10=38, so you would return a 38. Note that the direction is different in the 'num' and in the 'values' array. The least-significant digit in 'num' is on the RIGHT, but the number in the array to get paired with that least-significant digit is listed on the LEFT of the array. Note: The array will be at least as long as the number of digits in 'num'. Look at the test data for examples. test2021_04_29_APP1SLHL_placeValue(31748, [1, 1, 1, 1, 1, 1, 1, 1, 1]) → 23 test2021_04_29_APP1SLHL_placeValue(2148, [2, 2, 2, 2, 2, 2]) → 30 test2021_04_29_APP1SLHL_placeValue(234897, [2, 3, 4, 5, 6, 7, 8, 9, 10]) → 125 ...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: 250
Copyright Nick Parlante 2017 - privacy