From 0bbe323f70d47801326b5a7908578008febf8df5 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 23:00:38 +0200 Subject: [PATCH] Tag, lint, build --- README.md | 32 ++++++++++++++++++++++++++++++-- tag_database | 3 ++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f15c1af45..90e814bc8 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ * [Standard deviation](#standard-deviation) ### Media -* [Speech_synthesis (experimental)](#speech_synthesis-experimental) +* [Speech synthesis (experimental)](#speech-synthesis-experimental) ### Object * [Object from key value pairs](#object-from-key-value-pairs) @@ -99,6 +99,7 @@ * [Is string](#is-string) * [Is symbol](#is-symbol) * [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) @@ -818,7 +819,22 @@ const standardDeviation = (arr, usePopulation = false) => { [⬆ back to top](#table-of-contents) ## Media -undefined +### Speech synthesis (experimental) + +Use `SpeechSynthesisUtterance.voice` and `indow.speechSynthesis.getVoices()` to convert a message to speech. +Use `window.speechSynthesis.speak()` to play the message. + +Learn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance). + +```js +const speak = message => { + const msg = new SpeechSynthesisUtterance(message); + msg.voice = window.speechSynthesis.getVoices()[0]; + window.speechSynthesis.speak(msg); +}; +// speak('Hello, World') -> plays the message +``` + [⬆ back to top](#table-of-contents) ## Object @@ -1051,6 +1067,18 @@ const timeTaken = callback => { [⬆ back to top](#table-of-contents) +### Number to array of digits + +Convert the number to a string, use `split()` to convert build an array. +Use `Array.map()` and `parseInt()` to transform each value to an integer. + +```js +const digitize = n => (''+n).split('').map(i => parseInt(i)); +// digitize(2334) -> [2, 3, 3, 4] +``` + +[⬆ back to top](#table-of-contents) + ### Ordinal suffix of number Use the modulo operator (`%`) to find values of single and tens digits. diff --git a/tag_database b/tag_database index 01c21bce9..7f81cbec1 100644 --- a/tag_database +++ b/tag_database @@ -49,6 +49,7 @@ is-symbol:utility last-of-list:array measure-time-taken-by-function:utility median-of-array-of-numbers:array +number-to-array-of-digits:utility object-from-key-value-pairs:object object-to-key-value-pairs:object ordinal-suffix-of-number:utility @@ -68,7 +69,7 @@ shuffle-array:array similarity-between-arrays:array sleep:function sort-characters-in-string-(alphabetical):string -speech_synthesis-(experimental):media +speech-synthesis-(experimental):media standard-deviation:math sum-of-array-of-numbers:array swap-values-of-two-variables:utility