GG Utils
GG Utils collects utils for daily struggle
Usage
var gg = ; console; // trueconsole; // false var array = 637240var sortedArray = ggAlgorithm console // [0,2,3,4,6,7]
Installation
npm install gg-utils --save
API Reference
Algorithm
var algorithm = Algorithm;
bubbleSort(array)
Sorts an array from the minimum to the maximum.
Reference: https://en.wikipedia.org/wiki/Bubble_sort
var array = 37125812console // [1,2,3,5,7,8,12]
cocktailShakerSort(array)
Sorts an array from the minimum to the maximum.
Reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort
var array = 37125812console // [1,2,3,5,7,8,12]
combSort(array)
Sorts an array from the minimum to the maximum.
Reference: https://en.wikipedia.org/wiki/Comb_sort
var array = 37125812console //[1,2,3,5,7,8,12]
fibonacciNumber(n)
Returns the nth fibonacci number.
Reference: https://en.wikipedia.org/wiki/Fibonacci_number
console // 6765console // 102334155
fibonacciNumberRecursive(n)
Returns the nth fibonacci number using the recursive algorithm (slower than the iterative).
Reference: https://en.wikipedia.org/wiki/Fibonacci_number
console //6765console //102334155
gnomeSort(array)
Sorts an array from the minimum to the maximum.
Reference: https://en.wikipedia.org/wiki/Gnome_sort
var array = 637240console // [0,2,3,4,6,7]
quickSort(array)
Sorts an array from the minimum to the maximum.
Reference: https://en.wikipedia.org/wiki/Quicksort
var array = 637240console // [0,2,3,4,6,7]
sieveOfEratosthenes(n)
Produces an array with all primes not greater than n.
Reference: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
console // [0,1,2,3,5,7]console // [0,1,2,3,5,7,11,13,17,19,23,29]console // false
trialDivision(n)
Produces an array with prime factors of n.
Reference: https://en.wikipedia.org/wiki/Trial_division
console // [2,2,3]console // [17]console // [2,2,2,2,7,7]
Date
var date = Date;
isLeapYear(year)
Checks if year is a leap year.
Reference: https://en.wikipedia.org/wiki/Leap_year
console //trueconsole //falseconsole //trueconsole //false
timeDiff(from, to[,timezone])
Returns an object with the fields: days, hours, minutes and seconds of the time difference between from and to
console // {days: 1203, hours: 16, minutes: 54,seconds: 25}console //{days: 1323, hours: 15, minutes: 54, seconds: 25}
Network
var network = Network;
isMACAddress(MAC)
Checks if the string provided is a valid MAC address.
console //trueconsole //false
isIPV4(IPV4)
Checks if the string provided is a valid IPV4.
console // trueconsole // false
isIPV6(IPV6[,specialCheck])
Checks if the string provided is a valid IPV6. If specialCheck is true (default is false), the following IPV6 address will be treated as valid:
- ::/128
- ::1/128
- ::/96
- ::ffff:0:0/96
- fe80::/10
- fec0::/10
- fc00::/7
- ff00::/8"
console // trueconsole // trueconsole // trueconsole // trueconsole // falseconsole // false
simplifyIPV6(IPV6)
Simpliefies a valid IPV6.
console // 2001:db8::1428:57abconsole // 2001:db8:85a3::1319:8a2e:370:7344console // ::1console // false
Random
var random = Random;
arrayGeneratorInt(min,max,n)
Returns a random array of integers.
- min is minimum value
- max is the maximum value
- n is the size of the array (limit 10000000)
console // [3,5,8,0,1]console // [-29,-27,-28,13,-29,10,14,7,13,-5]console // falseconsole // false
getRandomIntInclusive(min,max)
Returns a random integer between min and max (both inclusive)
console // 4console // 10console // -8console // false
getRandomString(n)
Returns a random string with length n. Available chars are [a-zA-Z0-9].
console // 2jIPIcUMCvconsole // 65Biconsole // ""console // ""
License
MIT