Added weighted median function and tests

Ah, true. Yes, putting this in the `if` block seems like a good idea.