-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-the-temperature-2469.go
45 lines (31 loc) · 1.22 KB
/
convert-the-temperature-2469.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
/*
You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.
You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].
Return the array ans. Answers within 10-5 of the actual answer will be accepted.
Note that:
Kelvin = Celsius + 273.15
Fahrenheit = Celsius * 1.80 + 32.00
Example 1:
Input: celsius = 36.50
Output: [309.65000,97.70000]
Explanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.
Example 2:
Input: celsius = 122.11
Output: [395.26000,251.79800]
Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
Constraints:
0 <= celsius <= 1000
*/
// [NOTE] The instructions say to use an array but []float64 is actually a slice.
// This caused me to fail several times, lol.
func convertTemperature(celsius float64) []float64 {
// C --> K conversation (add to ans array)
k := celsius + 273.15
// C --> F conversation (add to ans array)
f := (celsius * 1.80) + 32.00
// Return ans array
var ans []float64
ans = append(ans, k)
ans = append(ans, f)
return ans
}