-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyu7_find_the_middle_element.go
50 lines (40 loc) · 1.13 KB
/
kyu7_find_the_middle_element.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
40
41
42
43
44
45
46
47
48
49
50
// As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the
// numerical element that lies between the other two elements;
// The input to the function will be an array of three distinct numbers (Haskell: a tuple);
//
// Example:
// gimme([2, 3, 1]) => 0
//
// 2 is the number that fits between 1 and 3 and the index of 2 in the input array is 0;
//
// Another example (just to make sure it is clear):
// gimme([5, 10, 14]) => 1
//
// 10 is the number that fits between 5 and 14 and the index of 10 in the input array is 1;
//
// https://www.codewars.com/kata/545a4c5a61aa4c6916000755
//
package kata
func MinMax(array [3]int) (int, int) {
max := array[0]
min := array[0]
for _, item := range array {
if max < item {
max = item
}
if min > item {
min = item
}
}
return min, max
}
func Gimme(array [3]int) int {
number := 0
min_value, max_value := MinMax(array)
for i := 0; i < 3; i++ {
if array[i] != min_value && array[i] != max_value {
number = i
}
}
return number
}