feat: Move and add functions
- Add global function randomFloatFrom() - Move getRandomColor() to app
This commit is contained in:
parent
0dfba8e6ee
commit
f83b5aa258
3 changed files with 23 additions and 12 deletions
|
|
@ -423,6 +423,12 @@ function randomIntFrom(min, max, pos = 0) {
|
|||
return Math.floor((Math.random() * (max - min + 1) + min) / pos) * pos;
|
||||
}
|
||||
|
||||
function randomFloatFrom(min, max, dec = 0) {
|
||||
dec = Math.pow(10, dec);
|
||||
|
||||
return Math.round((Math.random() * (max - min + 1) + min) * dec) / dec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ersetzt \n durch <br>.
|
||||
*
|
||||
|
|
@ -437,6 +443,22 @@ function replaceLineBreaks(text) {
|
|||
return text.split('\n').join('<br>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine zufällige Farbe als HEX-Wert aus.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
function getRandomColor() {
|
||||
const letters = '0123456789ABCDEF';
|
||||
let color = '#';
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
color += letters[Math.floor(Math.random() * 16)];
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// CONCEPTS
|
||||
|
||||
// NOTE: Benutzt private Zuweisungen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue