Created
June 16, 2015 17:34
-
-
Save dzsodzso63/e1efbfd2e938ca976af8 to your computer and use it in GitHub Desktop.
The Gilded Rose kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var GildedRose = function () { | |
console.log("OMGHAI!"); | |
var items = []; | |
items.push(new Item("+5 Dexterity Vest", 10, 20)); | |
items.push(new Item("Aged Brie", 2, 0)); | |
items.push(new Item("Elixir of the Mongoose", 5, 7)); | |
items.push(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); | |
items.push(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); | |
items.push(new Item("Conjured Mana Cake", 3, 6)); | |
GildedRose.updateQuality(items); | |
}; | |
GildedRose.updateQuality = function (items) { | |
for (var i = 0; i < items.length; i++) { | |
if ("Aged Brie" != items[i].name && "Backstage passes to a TAFKAL80ETC concert" != items[i].name) { | |
if (items[i].quality > 0) { | |
if ("Sulfuras, Hand of Ragnaros" != items[i].name) { | |
items[i].quality = items[i].quality - 1 | |
} | |
} | |
} else { | |
if (items[i].quality < 50) { | |
items[i].quality = items[i].quality + 1 | |
if ("Backstage passes to a TAFKAL80ETC concert" == items[i].name) { | |
if (items[i].sellIn < 11) { | |
if (items[i].quality < 50) { | |
items[i].quality = items[i].quality + 1 | |
} | |
} | |
if (items[i].sellIn < 6) { | |
if (items[i].quality < 50) { | |
items[i].quality = items[i].quality + 1 | |
} | |
} | |
} | |
} | |
} | |
if ("Sulfuras, Hand of Ragnaros" != items[i].name) { | |
items[i].sellIn = items[i].sellIn - 1; | |
} | |
if (items[i].sellIn < 0) { | |
if ("Aged Brie" != items[i].name) { | |
if ("Backstage passes to a TAFKAL80ETC concert" != items[i].name) { | |
if (items[i].quality > 0) { | |
if ("Sulfuras, Hand of Ragnaros" != items[i].name) { | |
items[i].quality = items[i].quality - 1 | |
} | |
} | |
} else { | |
items[i].quality = items[i].quality - items[i].quality | |
} | |
} else { | |
if (items[i].quality < 50) { | |
items[i].quality = items[i].quality + 1 | |
} | |
} | |
} | |
} | |
return items; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("GildedRose shop manager", function () { | |
it("does some stuff", function() { | |
expect(1).toBe(1); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Item = function (name, sellIn, quality) { | |
this.name = name; | |
this.sellIn = sellIn; | |
this.quality = quality; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment