I’m using Samba to track some of redemption/arcade games prizes that are won. One of our games gives out cards. For each card that is given out they can trade it in for 50 (redemption) tickets. If they collect 9 unique cards (each card is numbered from 1 thru 9) in a series they will get 5,000 tickets.
Each time a card is scanned (barcode scanner), I’m going to store that number in custom field in Tasks. This list will look something like this: 3,2,4,1,5,9,6,7,9,8
(for simplicity sake I will refer to the list as 1,2,3,4,5,6,7,8,9
). I have a script that will recognize when a the series is reached. The problem I am having trouble is counting the number of series are in the list.
I need to count the number of series in the list to award another 5,000 tickets when another series is entered in. Right now my script will recognize when the last number in the series is scanned in. But after that, any individual card is scanned in, it is going to see the original series again and add another 5,000 ticket.
Here is my script that recognizes when a series is reached:
function spongepineapple(arr) {
var arr = '1,2,3,4,5,6,7,9,7,2,5,4,5,8'
for (var i = 1; i <= 9; i++) {
if (arr.indexOf(i) === -1) {
return false;
}
}
return true;
}
This is what the internet keeps giving me on counting the series. I tried entering into Samba, but it keeps giving me errors (syntax or missing ‘:’):
function countOccurrences(arr) {
var arr = '1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9';
var counts = {};
// Initialize counts for numbers 1-9
for (let i = 1; i <= 9; i++) {
counts[i] = 0;
}
// Count occurrences
for (var num of arr) {
if (num >= 1 && num <= 9) {
counts[num]++;
}
}
return counts;
}
I hope this makes sense. If you need more context, let me know.
Any help is greatly appreciated.