Skip to content

Commit

Permalink
fix modulus bug for negative numbers 🤪
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolderup committed Dec 8, 2020
1 parent c8256dd commit 482a32c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/src/components/EditableScoreBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import patterns from '../lib/heropatterns';

import "./EditableScoreBoard.css";

// LMAOOOOOOOOOOO
Number.prototype.mod = function (n) {
return ((this % n) + n) % n;
};

function pickFontColor(rgb) {
const yiq = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
return (yiq >= 128) ? 'black' : 'white'
Expand Down Expand Up @@ -84,7 +89,7 @@ export default function EditableScoreBoard() {

function nextBackgroundPattern(e) {
e.preventDefault();
const newIndex = (pageStyle.backgroundImage.index + 1) % patterns.length;
const newIndex = (pageStyle.backgroundImage.index + 1).mod(patterns.length);
sendChanges(room, players, {
...pageStyle, backgroundImage: {
index: newIndex,
Expand All @@ -95,7 +100,7 @@ export default function EditableScoreBoard() {

function previousBackgroundPattern(e) {
e.preventDefault();
const newIndex = (pageStyle.backgroundImage.index - 1) % patterns.length;
const newIndex = (pageStyle.backgroundImage.index - 1).mod(patterns.length);
sendChanges(room, players, {
...pageStyle, backgroundImage: {
index: newIndex,
Expand Down

0 comments on commit 482a32c

Please sign in to comment.