From a5f99e68a2d4701accd30080672a3c7414a7d43d Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 16 Dec 2017 18:00:42 +0200 Subject: [PATCH] Tag and build --- README.md | 78 ++++++++++++++++++++++++++-------------------------- tag_database | 6 ++-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 123ea24f1..35808040d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ ### Date * [Get days difference between dates](#get-days-difference-between-dates) +* [JSON to date](#json-to-date) ### Function * [Chain asynchronous functions](#chain-asynchronous-functions) @@ -79,6 +80,8 @@ * [Hamming distance](#hamming-distance) * [Percentile](#percentile) * [Powerset](#powerset) +* [Random integer in range](#random-integer-in-range) +* [Random number in range](#random-number-in-range) * [Round number to n digits](#round-number-to-n-digits) * [Standard deviation](#standard-deviation) @@ -117,12 +120,9 @@ * [Is number](#is-number) * [Is string](#is-string) * [Is symbol](#is-symbol) -* [JSON to date](#json-to-date) * [Measure time taken by function](#measure-time-taken-by-function) * [Number to array of digits](#number-to-array-of-digits) * [Ordinal suffix of number](#ordinal-suffix-of-number) -* [Random integer in range](#random-integer-in-range) -* [Random number in range](#random-number-in-range) * [RGB to hexadecimal](#rgb-to-hexadecimal) * [URL parameters](#url-parameters) * [UUID generator](#uuid-generator) @@ -680,6 +680,20 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateIni // getDaysDiffBetweenDates(new Date("2017-12-13"), new Date("2017-12-22")) -> 9 ``` +[⬆ back to top](#table-of-contents) + +### JSON to date + +Use `Date()`, to convert dates in JSON format to readable format (`dd/mm/yyyy`). + +```js +const jsonToDate = arr => { + const dt = new Date(parseInt(arr.toString().substr(6))); + return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }` +}; +// jsonToDate(/Date(1489525200000)/) -> "14/3/2017" +``` + [⬆ back to top](#table-of-contents) ## Function @@ -935,6 +949,28 @@ const powerset = arr => [⬆ back to top](#table-of-contents) +### Random integer in range + +Use `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer. + +```js +const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; +// randomIntegerInRange(0, 5) -> 2 +``` + +[⬆ back to top](#table-of-contents) + +### Random number in range + +Use `Math.random()` to generate a random value, map it to the desired range using multiplication. + +```js +const randomInRange = (min, max) => Math.random() * (max - min) + min; +// randomInRange(2,10) -> 6.0211363285087005 +``` + +[⬆ back to top](#table-of-contents) + ### Round number to n digits Use `Math.round()` and template literals to round the number to the specified number of digits. @@ -1331,20 +1367,6 @@ const isSymbol = val => typeof val === 'symbol'; [⬆ back to top](#table-of-contents) -### JSON to date - -Use `Date()`, to convert dates in JSON format to readable format (`dd/mm/yyyy`). - -```js -const jsonToDate = arr => { - const dt = new Date(parseInt(arr.toString().substr(6))); - return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }` -}; -// jsonToDate(/Date(1489525200000)/) -> "14/3/2017" -``` - -[⬆ back to top](#table-of-contents) - ### Measure time taken by function Use `console.time()` and `console.timeEnd()` to measure the difference between the start and end times to determine how long the callback took to execute. @@ -1392,28 +1414,6 @@ const toOrdinalSuffix = num => { [⬆ back to top](#table-of-contents) -### Random integer in range - -Use `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer. - -```js -const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; -// randomIntegerInRange(0, 5) -> 2 -``` - -[⬆ back to top](#table-of-contents) - -### Random number in range - -Use `Math.random()` to generate a random value, map it to the desired range using multiplication. - -```js -const randomInRange = (min, max) => Math.random() * (max - min) + min; -// randomInRange(2,10) -> 6.0211363285087005 -``` - -[⬆ back to top](#table-of-contents) - ### RGB to hexadecimal Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (`<<`) and `toString(16)`, then `padStart(6,'0')` to get a 6-digit hexadecimal value. diff --git a/tag_database b/tag_database index ac64d168d..88532ea9f 100644 --- a/tag_database +++ b/tag_database @@ -55,7 +55,7 @@ is-function:utility is-number:utility is-string:utility is-symbol:utility -JSON-to-date:utility +JSON-to-date:date last-of-list:array log-function-name:function measure-time-taken-by-function:utility @@ -70,8 +70,8 @@ pick:array pipe-functions:function powerset:math promisify:function -random-integer-in-range:utility -random-number-in-range:utility +random-integer-in-range:math +random-number-in-range:math read-file-as-array-of-lines:node redirect-to-URL:browser reverse-a-string:string