refactoring (#4)

This commit is contained in:
2021-04-10 19:17:18 +02:00
committed by GitHub
parent 9cf66c7435
commit 24a07c4588
21 changed files with 240 additions and 173 deletions

6
functions/Compare.js Normal file
View File

@ -0,0 +1,6 @@
const Compare = () => {
return { result };
};
module.exports = { Compare };

View File

@ -0,0 +1,7 @@
const CountOccurences = (arr, value) => {
return arr.filter((v) => (v === value)).length;
};
module.exports = { CountOccurences };
//console.log(countOccurrences([1,2,3,4,3,2,3,3,2],2));

15
functions/Roll.js Normal file
View File

@ -0,0 +1,15 @@
const Random = require('random');
const roll = (numberOfDice, numberOfEyes, tag) => {
let dice = [];
let sum = 0;
if(tag) {
Random.use(tag);
}
for (let i = 0; i<numberOfDice; i++ ) {
let result = Random.int(1,numberOfEyes);
dice.push(result);
sum += result;
}
return { dice, sum };
};
module.exports = { roll };

7
functions/findMessage.js Normal file
View File

@ -0,0 +1,7 @@
const globals = require('../globals');
const findMessage = (value) => {
return globals.Replies.find(r => r.id === value).string;
};
module.exports = { findMessage };