Skip to content

Instantly share code, notes, and snippets.

@nbeers22
Created March 31, 2019 11:44
Show Gist options
  • Save nbeers22/9c01a228e2df40385604d618d8a0ff42 to your computer and use it in GitHub Desktop.
Save nbeers22/9c01a228e2df40385604d618d8a0ff42 to your computer and use it in GitHub Desktop.
Thinful JavaScript number functions
// Create a function called computeArea that takes two arguments: width and height.
// It returns the area of a rectangle whose width is width and height is height.
// So computeArea(2, 2) would return 4, and computeArea(3, 5) would return 15.
const computeArea = (width, height) => width * height;
// Create 2 functions, one called celsToFahr that converts Celsius to Fahrenheit and
// another called fahrToCels that converts Fahrenheit to Celsius. celsToFahr takes one
// argument, celsTemp, and fahrToCels takes one argument, fahrTemp.
// [°F] = [°C] × ​9⁄5 + 32
// [°C] = ([°F] − 32) × ​5⁄9
const celsToFahr = celsTemp => (celsTemp * (9 / 5)) + 32
const fahrToCels = fahrTemp => (fahrTemp - 32) * (5 / 9)
// Write a function called isDivisible that takes 2 arguments: divisee and divisor.
// This function should return true if divisee can be divided by divisor with no remainder,
// otherwise, it should return false. So isDivisible(18, 3) should be true, while isDivisible(15, 4)
// should be false.
const isDivisible = (divisee, divisor) => divisee % divisor === 0 ? true : false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment