TRAITS: Largest: refactor to not need Copy trait

Return reference to list element
This commit is contained in:
laurens 2020-09-06 16:59:28 +02:00
parent 4ed58084c2
commit c091a91f2a

View file

@ -1,7 +1,7 @@
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
let mut largest = list[0];
fn largest<T: PartialOrd>(list: &[T]) -> &T {
let mut largest = &list[0];
for &item in list {
for item in list {
if item > largest {
largest = item;
}