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

[Codewars] Plural (8 kyu) / JavaScript

by fluss 2023. 2. 5.

https://www.codewars.com/kata/52ceafd1f235ce81aa00073a

 

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:

We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as 5 minutes, 14 apples, or 1 sun.

You only need to worry about english grammar rules for this kata, where anything that isn't singular (one of something), it is plural (not one of something).

All values will be positive integers or floats, or zero.

 

코드

function plural(n) {
  return n !== 1;
}

댓글