-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyu7_the_highest_profit_wins.go
39 lines (33 loc) · 1.07 KB
/
kyu7_the_highest_profit_wins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Story
// Ben has a very simple idea to make some profit: he buys something and sells it again. Of course, this wouldn't give
// him any profit at all if he was simply to buy and sell it at the same price. Instead, he's going to buy it for the
// lowest possible price and sell it at the highest;
//
// Task
// Write a function that returns both the minimum and maximum number of the given list/array;
//
// Examples (Input-->Output):
// [1,2,3,4,5] --> [1,5]
// [2334454,5] --> [5,2334454]
// [1] --> [1,1]
//
// Remarks
// All arrays or lists will always have at least one element, so you don't need to check the length. Also, your
// function will always get an array or a list, you don't have to check for null, undefined or similar;
//
// https://www.codewars.com/kata/559590633066759614000063
//
package kata
func MinMax(arr []int) [2]int {
max := arr[0]
min := arr[0]
for _, item := range arr {
if max < item {
max = item
}
if min > item {
min = item
}
}
return [2]int{min, max}
}