class Number
Number helper
As for all helpers, all methods are statics.
For convenience, the best practice is to use:
use Library\Helper\Number as NumberHelper;
Methods
static bool |
isOdd(int $val = null)
Test if an integer is an "odd number" |
|
static bool |
isEven(int $val = null)
Test if an integer is an "even number" |
|
static bool |
isPrime(int $val = null)
Test if an integer is a "prime number" |
|
static int |
getFibonacciItem(int $val = null)
Get the |
|
static int |
getLuhnKey(int $val = null)
Luhn formula: get the Luhn digit of an integer |
|
static bool |
isLuhn(int $val = null)
Check that the last number in a suite is its Luhn key |
|
static int |
getSumOfDigits($val $val = null)
Calculate the sum of the digits of a number (its absolute entire value) |
|
static bool |
isSelfDescribing($val $val = null)
Test if a number is "self-describing": |
|
static bool |
isJollyJumperSeries(array $items = array())
Test if a series of numbers is a "Jolly Jumper": |
Details
at line 46
static public bool
isOdd(int $val = null)
Test if an integer is an "odd number"
at line 60
static public bool
isEven(int $val = null)
Test if an integer is an "even number"
at line 74
static public bool
isPrime(int $val = null)
Test if an integer is a "prime number"
at line 99
static public int
getFibonacciItem(int $val = null)
Get the $val
element of the Fibonacci suite
at line 123
static public int
getLuhnKey(int $val = null)
Luhn formula: get the Luhn digit of an integer
7992739871 => 3
at line 154
static public bool
isLuhn(int $val = null)
Check that the last number in a suite is its Luhn key
at line 169
static public int
getSumOfDigits($val $val = null)
Calculate the sum of the digits of a number (its absolute entire value)
at line 195
static public bool
isSelfDescribing($val $val = null)
Test if a number is "self-describing":
assuming digit positions are labeled 0 to N-1, the digit in each position is equal to the number of times that digit appears in the number
2020 => true 22 => false 1210 => true
at line 220
static public bool
isJollyJumperSeries(array $items = array())
Test if a series of numbers is a "Jolly Jumper":
A sequence of n > 0 integers where the absolute values of the differences between successive elements take on all possible values 1 through n - 1.