7 kyu

Simple Maths Test

1,319 of 3,277sohilpandya

Description:

Create a function which checks a number for three different properties.

  • is the number prime?
  • is the number even?
  • is the number a multiple of 10?

Each should return either true or false, which should be given as an array. Remark: The Haskell variant uses data Property.

Examples

numberProperty(7)  // ==> [true,  false, false] 
numberProperty(10) // ==> [false, true,  true] 
number_property(7)  # ==> [true,  false, false] 
number_property(10) # ==> [false, true,  true] 
number_property(7)  # ==> [true,  false, false] 
number_property(10) # ==> [false, true,  true] 
numberProperty 7  `shouldBe` Property True  False False
numberProperty 10 `shouldBe` Property False True  True
Kata.NumberProperty(7)  => new bool[] {true, false, false}
Kata.NumberProperty(10) => new bool[] {false, true, true}
SimpleMath.numberProperty(7)  => new boolean[] {true, false, false}
SimpleMath.numberProperty(10) => new boolean[] {false, true, true}

The number will always be an integer, either positive or negative. Note that negative numbers cannot be primes, but they can be multiples of 10:

numberProperty(-7)  // ==> [false, false, false] 
numberProperty(-10) // ==> [false, true,  true] 
number_property(-7)  # ==> [false, false, false] 
number_property(-10) # ==> [false, true,  true] 
number_property(-7)  # ==> [false, false, false] 
number_property(-10) # ==> [false, true,  true] 
numberProperty (-7)  `shouldBe` Property False False False
numberProperty (-10) `shouldBe` Property False True  True
Kata.NumberProperty(-7)  => new bool[] {false, false, false}
Kata.NumberProperty(-10) => new bool[] {false, true, true}
SimpleMath.numberProperty(-7)  => new boolean[] {false, false, false}
SimpleMath.numberProperty(-10) => new boolean[] {false, true, true}
Algorithms
Mathematics

More By Author:

Check out these other kata created by sohilpandya

Stats:

CreatedMar 16, 2015
PublishedMar 16, 2015
Warriors Trained6538
Total Skips425
Total Code Submissions22970
Total Times Completed3277
JavaScript Completions1319
Haskell Completions190
Ruby Completions405
Python Completions1128
C# Completions183
Java Completions168
Total Stars74
% of votes with a positive feedback rating88% of 364
Total "Very Satisfied" Votes296
Total "Somewhat Satisfied" Votes51
Total "Not Satisfied" Votes17
Ad
Contributors
  • sohilpandya Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • bkaes Avatar
  • GiacomoSorbi Avatar
  • Darnor Avatar
  • aweleshetu Avatar
  • Voile Avatar
  • Madjosz Avatar
  • Souzooka Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad