You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square.
If it is a square, return its area. If it is a rectangle, return its perimeter.
area_or_perimeter(6, 10)
--> 32
area_or_perimeter(4, 4)
--> 16
Tests
area_or_perimeter(5, 5)
area_or_perimeter(10, 20)
Good luck!
This challenge comes from no one
on CodeWars. 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 (9)
ooga booga
:)
Here is the simple solution with Python:
In js:
let area_or_perimeter = (x, y) => x === y ? x*y : 2*(x+y);
Pass all the tests.
In Kotlin it would be:
It's quite simple, check whether a=b if it's true return a*b if it's not, return (a+b)*2.