Added weighted median function and tests

Sorry, a second look-through and I have more. This should be  `middle((v[permute[i-2]], v[permute[i-1]])` and the below case should be `middle(v[permute[i-1]])` for type stability.