1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Math.rand = function(bound) { return Math.floor(Math.random() * bound) };
const alphabet = Array.from('abcdefghijklmnopqrstuvwxyz');
function getInventoryItem(string, index) {
const regex = new RegExp('((\\w{2}\\|\\w{1}\\|\\d{1,2});(' + index + '))');
const totalitems = string.match(new RegExp(/(\w{2}\|\w{1}\|\d{1,2});(\d{1,2})/g)).length;
console.log(`total items: ${totalitems}`);
return string.match(regex)[0];
}
function makeRandomInventory(size) {
let str = "";
for (let i = 0; i < size; i++) {
str += alphabet[Math.rand(26)].toUpperCase() + alphabet[Math.rand(26)].toUpperCase() + '|' + Array.from('CRELM')[Math.rand(4)] + '|' + Math.rand(50) + ';' + i + '\n';
}
console.log(str);
return str;
}
console.log(getInventoryItem(makeRandomInventory(50), 4));