about | help | code help+videos | done | prefs |
test2025_05_22_BONUS_tooFar
Write a method that returns an array of the same length as 'nums' but with ONLY the numbers that are in range of the 'safeNum'. To be in range means that the POSITION of the number is within 'maxDist' distance from a 'safeNum'. For example, in the array {15,200,4,10,7000,80,59,33,50,10,17,200,530} with a 'safeNum' of 10 and a 'maxDist' of 1, you would return {4,10,7000,50,10,17,0,0,0,0,0,0,0}. This is because these are the numbers that are at most 1 POSITION away from a 10. As preconditions you may assume that the length of the 'nums' array is at most 100. You may also assume that 'maxDist' is non-negative. Note that you may NOT assume that 'safeNum' appears in the array. If 'safeNum' never appears in the array, then none of the numbers are included in the result. If 'maxDist' is zero, then ONLY the 'safeNum' itself appears in the result. test2025_05_22_BONUS_tooFar([234, 35, 46, 24, 4, 57, 4, 856, 235, 57, 235, 124, 75, 3457, 24, 463, 4, 23, 7, 8], 4, 3) → [35, 46, 24, 4, 57, 4, 856, 235, 57, 3457, 24, 463, 4, 23, 7, 8, 0, 0, 0, 0] test2025_05_22_BONUS_tooFar([24, 3, 34645, 23, 24, 64, 32, 463, 41, 564, 7, 412, 57, 866, 424, 457, 3255, 658, 241], 41, 30) → [24, 3, 34645, 23, 24, 64, 32, 463, 41, 564, 7, 412, 57, 866, 424, 457, 3255, 658, 241] test2025_05_22_BONUS_tooFar([24, 3, 34645, 23, 24, 64, 32, 463, 41, 564, 7, 412, 57, 866, 424, 457, 3255, 658, 241], 41, 5) → [23, 24, 64, 32, 463, 41, 564, 7, 412, 57, 866, 0, 0, 0, 0, 0, 0, 0, 0] ...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