Skip to content

Instantly share code, notes, and snippets.

@mebtte
mebtte / getRandomInteger.js
Created April 24, 2019 08:10
Get a random integer.
/**
* Get a random integer.
* @author mebtte<mebtte@gamil.com>
* @param {Number} [min] Minimum integer, default `0`.
* @param {Number} [max] Maximum integer, default `1`.
* @return {Number} A random integer between `min` and `max` that include `min` but do not include `max`.
*/
function getRandomInteger(min = 0, max = 1) {
return Math.floor(min + Math.random() * (max - min));
}
@mebtte
mebtte / .gitignore
Created April 21, 2019 07:19
git ignore
# node.js & npm & yarn
node_modules/
package-lock.json
yarn.lock
# macOS
.DS_Store
# Windows
@mebtte
mebtte / getRandomString.js
Last active April 21, 2019 07:15
Get a random string.
/**
* Get a random string.
* @author mebtte<mebtte@gamil.com>
* @param {String} [length] The length of string, detault `10`.
* @return {String} A random string.
*/
function getRandomString(length = 10) {
const randomChars = [
"0",
"1",
@mebtte
mebtte / typeOf.js
Last active April 21, 2019 07:16
Get the type of value.
/**
* Get the type of value.
* @author mebtte<mebtte@gmail.com>
* @param {Any} [value] value
* @return {String} enum(Undefined, Null, Boolean, Number, String, Symbol, Object, Function, Array, Set, WeakSet, Map, WeakMap, NodeList)
*/
function typeOf(value) {
return Object.prototype.toString.call(value).match(/\[object (\S*)\]/)[1];
}