Skip to content

Instantly share code, notes, and snippets.

@joevandyk
Last active June 3, 2017 00:18
Show Gist options
  • Save joevandyk/300b091100d072b8c07f50171898fc2b to your computer and use it in GitHub Desktop.
Save joevandyk/300b091100d072b8c07f50171898fc2b to your computer and use it in GitHub Desktop.
interface BingoStatus {
won: boolean
}
interface BingoCell {
number: string,
freebie?: boolean,
completed?: boolean
}
interface BingoCard extends Array<Array<BingoCell>>{}
interface BingoGame {
card: BingoCard
status: BingoStatus
}
interface BingoEntry {
user_id: string,
number: string
}
function buildCard(template: BingoCard, entries: BingoEntry[]): BingoCard {
for (let entry of entries) {
for (let row of template) {
for (let cell of row) {
if (entry.number == cell.number) {
cell.completed = true
}
}
}
}
return template
}
/// TESTS
import { expect } from 'chai';
import {} from "mocha";
describe('Bingo', () => {
it('should build a card', () => {
let cardTemplate: BingoCard = [
[
{number: "Tenderloin Steak"},
{number: "Ground Beef"},
{number: "Rib Eye"},
],
[
{number: "Top Round"},
{number: "Freebie", freebie: true, completed: true},
{number: "Bottom Round"},
],
[
{number: "Beef Jerky"},
{number: "Leaf Fat"},
{number: "Kidneys"},
],
]
let entries = [{user_id: '1', number: 'Top Round'}, {user_id: '1', number: 'Ground Beef'}]
let card = buildCard(cardTemplate, entries)
let expected: BingoCard = [
[
{number: "Tenderloin Steak"},
{number: "Ground Beef", completed: true},
{number: "Rib Eye"},
],
[
{number: "Top Round", completed: true},
{number: "Freebie", freebie: true, completed: true},
{number: "Bottom Round"},
],
[
{number: "Beef Jerky"},
{number: "Leaf Fat"},
{number: "Kidneys"},
],
]
expect(card).to.deep.equal(expected)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment