You are given two angles of a triangle in degrees.
Write a function to return the third angle. Only positive integers will be tested.
Sample Tests:
thirdAngle(30, 60)
thirdAngle(60, 60)
thirdAngle(43, 78)
thirdAngle(10, 20)
This challenge comes from user5651159. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (16)
ANSI C
Run with
~$ gcc -lm <file_name> && ./a.out
Kept it simple
My solution in js
What happens if I enter
thirdAngle(0,0)
?Good catch. Edited. But the challenge is to deal with positive integers so didn't take 0 into account as it is neither positive nor negative integer.
True enough. But why code purely for specs when coding for the edge and error cases takes just a few more minutes?
Elm
Test it online
Here.
This oughta do it for Elixir.
In Go!
Go Playground
Solution in APL
(using Dyalog APL)
Tests:
Try it online!
Keeping it simple in bash
Running through the examples on the cmd:
BTW the challenge on Kata only tests for valid triangles,
was sufficient in JS
What happens if I enter
thirdAngle(0,0)
?you are right, I just wrote it very fast and I did not think about this case.
TDD will help a lot in these situations.