From 9c0998c29ab44e5370871a16732c0eb1ef5dc87f Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Thu, 15 Sep 2016 22:02:11 -0500 Subject: [PATCH] refactor(client): extract find pet logic into function --- website/client-old/js/controllers/inventoryCtrl.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/website/client-old/js/controllers/inventoryCtrl.js b/website/client-old/js/controllers/inventoryCtrl.js index 9bfe5ddfa7..20a5c0837d 100644 --- a/website/client-old/js/controllers/inventoryCtrl.js +++ b/website/client-old/js/controllers/inventoryCtrl.js @@ -378,18 +378,22 @@ habitrpg.controller("InventoryCtrl", }; $scope.shouldShowPremiumMountSection = function () { - var pets = Object.keys(user.items.pets); - return pets.find(function (petKey) { - var pet = Content.petInfo[petKey]; + return findPet(function (pet) { return pet.type === 'premium'; }); }; $scope.hasAPetOfPotion = function (potion) { + return findPet(function (pet) { + return pet.potion === potion; + }); + }; + + function findPet (fn) { var pets = Object.keys(user.items.pets); return pets.find(function (petKey) { var pet = Content.petInfo[petKey]; - return pet.potion === potion; + return fn(pet); }); }