-
Notifications
You must be signed in to change notification settings - Fork 0
/
generators.js
38 lines (34 loc) · 1.28 KB
/
generators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const getValues = () => {
const sequenceAmount = document.getElementById("sequences-amount").value || 0;
const sequencesMinLength = document.getElementById("sequences-min-length").value || 0;
const sequencesMaxLength = document.getElementById("sequences-max-length").value || 0;
const alphabetValue = document.getElementById("alphabet").value || "";
const alphabet = alphabetValue.split(",");
return {
amount: sequenceAmount,
min: sequencesMinLength,
max: sequencesMaxLength,
alphabet
};
}
const generateSequences = ({amount, min, max, alphabet}) => {
const sequences = [];
for (let index = 0; index < amount; index++) {
const size = Math.floor(Math.random() * (max - min + 1) + min);
let sequence = "";
for (let i = 0; i < size; i++) {
const pos = Math.floor(Math.random() * alphabet.length);
sequence += alphabet[pos];
}
sequences.push(sequence);
}
return sequences;
}
const displaySequences = () => {
const sequences = generateSequences(getValues());
const display = document.getElementById("display");
display.innerHTML = "";
sequences.map(sequence => {
display.innerHTML += `<input class="sequence" value="${sequence}">`;
});
}