forked from HackYourFuture-CPH/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyfBayHelpers.js
More file actions
72 lines (64 loc) · 1.55 KB
/
Copy pathhyfBayHelpers.js
File metadata and controls
72 lines (64 loc) · 1.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* DONT MODIFY ANY OF THIS CODE!!!*/
window.getAvailableProducts = function() {
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomItem(availableProductNames) {
return availableProductNames[
getRandomInt(0, availableProductNames.length - 1)
];
}
function getRandomProductname() {
const preWords = [
"Used",
"Fantastic",
'"Used"',
"Broken",
"Beautiful",
"Wet",
"Green",
"Sloppy",
"Dirty"
];
const productNames = [
"Carrot",
"Drone",
"Giftcard",
"Puppy",
"Car",
"Shirt",
"Milk",
"Chalk",
"Fish fingers",
"Socks",
"Chocolate",
"Toothbrush",
"Computer",
"Nokia",
"Cologne"
];
let chosenProductName = getRandomItem(productNames);
const shouldHavePreWord = getRandomInt(0, 10) > 6;
if (shouldHavePreWord) {
const preWord = preWords[getRandomInt(0, preWords.length - 1)];
chosenProductName = `${preWord} ${chosenProductName}`;
}
return chosenProductName;
}
const numberOfAvailableProducts = getRandomInt(0, 30);
const availableProducts = Array.apply(
null,
Array(numberOfAvailableProducts)
).map(() => {
const name = getRandomProductname();
return {
id: `${name}${getRandomInt(0, 100000)}`,
name,
price: getRandomInt(0, 10000),
rating: getRandomInt(1, 10)
};
});
return availableProducts;
};