본문 바로가기
알고리즘/Codewars

[Codewars] Area or Perimeter (8 kyu) / JavaScript

by fluss 2023. 2. 11.

https://www.codewars.com/kata/5ab6538b379d20ad880000ab

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

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.

 

Example(Input1, Input2 --> Output):

6, 10 --> 32
3, 3 --> 9

Note: for the purposes of this kata you will assume that it is a square if its length and width are equal, otherwise it is a rectangle.

 

코드

const areaOrPerimeter = function(l , w) {
  return l === w ? l * w : (l + w) * 2;
};

댓글