Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function specificWinrate(type, address) {
- var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
- var winLoss = sheet.getRange(address);
- var sheetValues = sheet.getSheetValues(1, 1, 200, 200);
- var game = winLoss.offset(-winLoss.getRow()+1, 0);
- var gameRegex = new RegExp("^" + type.toString(), "i");
- var winRegex = new RegExp("^w", "i");
- var lossRegex = new RegExp("^l", "i");
- var listGames = [];
- var cGame = "start";
- var cWinLoss = "";
- var wins = 0;
- var losses = 0;
- while (true) {
- cWinLoss = sheetValues[winLoss.getRow()-1][winLoss.getColumn()-1];
- cGame = sheetValues[game.getRow()-1][game.getColumn()-1];
- if (cGame === "") break;
- if (cGame.match(gameRegex)) {
- if (cWinLoss.match(winRegex)) {
- wins = wins + 1;
- }
- else if (cWinLoss.match(lossRegex)) {
- losses = losses + 1;
- }
- }
- winLoss = winLoss.offset(0,1);
- game = game.offset(0,1);
- }
- if (losses + wins === 0) return "";
- return wins / (losses + wins);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement