How to average elements in one array based on values in another array? <pre><code>let tiedArray = [|9.4;1.2;-3.4;-3.4;-3.4;-3.4;-10.0|]; let sortedArray = [|-10.0;-3.4;-3.4;-3.4;-3.4;1.2;9.4|]; let sortedArrayRanks = [|1.;2.;3.;4.;5.;6.;7.|]; let desired_ranked_array = [|1.;3.5;3.5;3.5;3.5;6.;7.|] </code></pre> <p>hello-</p> <p>I am trying to write a function that takes 2 arrays (sortedArray and sortedArrayRanks) and return an output array like the one below. The mapping function in this example would take 2,3,4, and 5 in sortedArrayRanks and see that they all have the same value in sortedArray, and instead replace all of those numbers in an output array with the average of them (which is 3.5)</p> <p>What's tripping me up is whether to use recursion or an imperative looping contruct, like loop through sorted array, and see if an item is the same one that preceded it, and then if it matches, check the one before it, etc. How can this be solved? Thanks!</p>