Merge pull request #300 from Asartea/asartea-patch-1-solutions
tempConversion: Update function names to account for changes in the base branch
This commit is contained in:
commit
44a95b8e89
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
|
Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
|
||||||
```
|
```
|
||||||
ftoc(32) // fahrenheit to celsius, should return 0
|
convertToCelsius(32) // fahrenheit to celsius, should return 0
|
||||||
|
|
||||||
ctof(0) // celsius to fahrenheit, should return 32
|
convertToFahrenheit(0) // celsius to fahrenheit, should return 32
|
||||||
```
|
```
|
||||||
|
|
||||||
Because we are human, we want the result temperature to be rounded to one decimal place: i.e., `ftoc(100)` should return `37.8` and not `37.77777777777778`.
|
Because we are human, we want the result temperature to be rounded to one decimal place: i.e., `convertToCelsius(100)` should return `37.8` and not `37.77777777777778`.
|
||||||
|
|
||||||
This exercise asks you to create more than one function so the `module.exports` section of the spec file looks a little different this time. Nothing to worry about, we're just packaging both functions into a single object to be exported.
|
This exercise asks you to create more than one function so the `module.exports` section of the spec file looks a little different this time. Nothing to worry about, we're just packaging both functions into a single object to be exported.
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
const ftoc = function(f) {
|
const convertToCelsius = function(fahrenheit) {
|
||||||
return Math.round((f - 32) * (5/9) * 10) / 10;
|
return Math.round((fahrenheit - 32) * (5/9) * 10) / 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctof = function(c) {
|
const convertToFahrenheit = function(celsius) {
|
||||||
return Math.round(((c * 9/5) + 32) * 10) / 10;
|
return Math.round(((celsius * 9/5) + 32) * 10) / 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ftoc,
|
convertToCelsius,
|
||||||
ctof
|
convertToFahrenheit
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
const {ftoc, ctof} = require('./tempConversion')
|
const {convertToCelsius, convertToFahrenheit} = require('./tempConversion')
|
||||||
|
|
||||||
describe('ftoc', () => {
|
describe('convertToCelsius', () => {
|
||||||
test('works', () => {
|
test('works', () => {
|
||||||
expect(ftoc(32)).toEqual(0);
|
expect(convertToCelsius(32)).toEqual(0);
|
||||||
});
|
});
|
||||||
test.skip('rounds to 1 decimal', () => {
|
test.skip('rounds to 1 decimal', () => {
|
||||||
expect(ftoc(100)).toEqual(37.8);
|
expect(convertToCelsius(100)).toEqual(37.8);
|
||||||
});
|
});
|
||||||
test.skip('works with negatives', () => {
|
test.skip('works with negatives', () => {
|
||||||
expect(ftoc(-100)).toEqual(-73.3);
|
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ctof', () => {
|
describe('convertToFahrenheit', () => {
|
||||||
test.skip('works', () => {
|
test.skip('works', () => {
|
||||||
expect(ctof(0)).toEqual(32);
|
expect(convertToFahrenheit(0)).toEqual(32);
|
||||||
});
|
});
|
||||||
test.skip('rounds to 1 decimal', () => {
|
test.skip('rounds to 1 decimal', () => {
|
||||||
expect(ctof(73.2)).toEqual(163.8);
|
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||||
});
|
});
|
||||||
test.skip('works with negatives', () => {
|
test.skip('works with negatives', () => {
|
||||||
expect(ctof(-10)).toEqual(14);
|
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue