-
Notifications
You must be signed in to change notification settings - Fork 0
/
grasshopperDebug.js
34 lines (25 loc) · 1.2 KB
/
grasshopperDebug.js
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
// Your friend is traveling abroad to the United States so he wrote a program to convert fahrenheit to celsius. Unfortunately his code has some bugs.
// Find the errors in the code to get the celsius converter working properly.
// To convert fahrenheit to celsius:
// celsius = (fahrenheit - 32) * (5/9)
// Remember that typically temperatures in the current weather conditions are given in whole numbers. It is possible for temperature sensors to report temperatures with a higher accuracy such as to the nearest tenth. Instrument error though makes this sort of accuracy unreliable for many types of temperature measuring sensors.
// SOLUTION v1
function weatherInfo(temp) {
var c = convertToCelsius(temp)
if (c <= 0)
return (c + " is freezing temperature")
else
return (c + " is above freezing temperature")
}
function convertToCelsius (temperature) {
var celsius = (temperature - 32) * (5/9)
return celsius
}
// SOLUTION v2:: More cryptic, less readable? The refactor is real.
const weatherInfo = t => {
var c = toCelcius(t)
return c <= 0 ? `${c} is freezing temperature` : `${c} is above freezing temperature`
}
const toCelcius = temp => {
return (temp - 32) * (5/9)
}