-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
53 lines (43 loc) · 1.25 KB
/
functions.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export const shuffleArr = (array) => {
const newArray = [...array];
var currentIndex = newArray.length,
temporaryValue,
randomIndex;
// While there remain elements to shuffleArr...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = newArray[currentIndex];
newArray[currentIndex] = newArray[randomIndex];
newArray[randomIndex] = temporaryValue;
}
return newArray;
};
export const getRandom = (upperLimit) => {
const arrayNum = [...Array(upperLimit)].map((_, i) => i);
const ranNums = shuffleArr(arrayNum);
return ranNums;
};
export const loadSounds = (length) => {
const soundArray = new Array(length);
for (let i = 0; i < soundArray.length; i++) {
const relPath = "./sounds/";
const fileType = ".mp3";
const srcLink = `${relPath}${i}${fileType}`;
soundArray[i] = new Howl({
src: [`${srcLink}`],
volume: 0.2,
});
}
return soundArray;
};
export const makeImg = (name) => {
const img = new Image();
const path = "./images/";
const fileType = ".png";
const imgStr = `${path}${name}${fileType}`;
img.src = imgStr;
return img;
};