Kata of the Day #21

Plural

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #21

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.

TypeScript


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

console.log(plural(100));

Go


package main

import (
	"fmt"
)

func plural(n int) bool {
  return n != 1
}

func main() {
	fmt.Println(plural(100))
}

Python


def plural(n):
    return n != 1

print(plural(100))

PHP


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

echo print_r(plural(100));

Go to Kata
ByJulie Kohl

Need some help?

Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.

Let's see
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe