@@ -3016,8 +3016,13 @@ impl<T> [T] {
3016
3016
/// ```
3017
3017
/// let mut v = [-5i32, 4, 2, -3, 1];
3018
3018
///
3019
- /// // Find the median
3020
- /// v.select_nth_unstable(2);
3019
+ /// // Find the items less than or equal to the median, the median, and greater than or equal to
3020
+ /// // the median.
3021
+ /// let (lesser, median, greater) = v.select_nth_unstable(2);
3022
+ ///
3023
+ /// assert!(lesser == [-3, -5] || lesser == [-5, -3]);
3024
+ /// assert_eq!(median, &mut 1);
3025
+ /// assert!(greater == [4, 2] || greater == [2, 4]);
3021
3026
///
3022
3027
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
3023
3028
/// // about the specified index.
@@ -3067,8 +3072,13 @@ impl<T> [T] {
3067
3072
/// ```
3068
3073
/// let mut v = [-5i32, 4, 2, -3, 1];
3069
3074
///
3070
- /// // Find the median as if the slice were sorted in descending order.
3071
- /// v.select_nth_unstable_by(2, |a, b| b.cmp(a));
3075
+ /// // Find the items less than or equal to the median, the median, and greater than or equal to
3076
+ /// // the median as if the slice were sorted in descending order.
3077
+ /// let (lesser, median, greater) = v.select_nth_unstable_by(2, |a, b| b.cmp(a));
3078
+ ///
3079
+ /// assert!(lesser == [4, 2] || lesser == [2, 4]);
3080
+ /// assert_eq!(median, &mut 1);
3081
+ /// assert!(greater == [-3, -5] || greater == [-5, -3]);
3072
3082
///
3073
3083
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
3074
3084
/// // about the specified index.
@@ -3122,8 +3132,13 @@ impl<T> [T] {
3122
3132
/// ```
3123
3133
/// let mut v = [-5i32, 4, 1, -3, 2];
3124
3134
///
3125
- /// // Return the median as if the array were sorted according to absolute value.
3126
- /// v.select_nth_unstable_by_key(2, |a| a.abs());
3135
+ /// // Find the items less than or equal to the median, the median, and greater than or equal to
3136
+ /// // the median as if the slice were sorted according to absolute value.
3137
+ /// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs());
3138
+ ///
3139
+ /// assert!(lesser == [1, 2] || lesser == [2, 1]);
3140
+ /// assert_eq!(median, &mut -3);
3141
+ /// assert!(greater == [4, -5] || greater == [-5, 4]);
3127
3142
///
3128
3143
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
3129
3144
/// // about the specified index.
0 commit comments