Skip to content

Instantly share code, notes, and snippets.

@theterminalguy
Created December 20, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theterminalguy/8a78751034355e97a247b7e816f41fe8 to your computer and use it in GitHub Desktop.
Save theterminalguy/8a78751034355e97a247b7e816f41fe8 to your computer and use it in GitHub Desktop.
Live Coding
// Write a function that takes an object. The object contains a left, right and operator properties. The left and right properties are numbers. The operator property is a string. The function should return the result of the operation. The function should return null if the operator is not one of the following: +, -, *, /.
// Example:
// calculate({ left: 1, right: 2, operator: '+' }) // 3
// calculate({ left: 1, right: 2, operator: '-' }) // -1
// calculate({ left: 1, right: 2, operator: '*' }) // 2
// calculate({ left: 1, right: 2, operator: '/' }) // 0.5
// calculate({ left: 1, right: 2, operator: '%' }) // null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment