From 37967f5bfb4f77bcc90c39fa06532fd995781059 Mon Sep 17 00:00:00 2001 From: Riccardo Padovani Date: Wed, 25 Oct 2017 17:11:18 +0200 Subject: [PATCH] Simplify code Signed-off-by: Riccardo Padovani --- js/controller/ListController.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/js/controller/ListController.js b/js/controller/ListController.js index 8b9aea80e..e23f3448b 100644 --- a/js/controller/ListController.js +++ b/js/controller/ListController.js @@ -28,21 +28,19 @@ app.controller('ListController', function ($scope, $location, $filter, BoardServ var boardKeys = Object.keys(boards); var colorOccurrences = []; - for (var i =0; i < boardKeys.length; i++) { - var key = boardKeys[i]; + for (var i = 0; i < $scope.colors.length; i++) { + colorOccurrences.push(0); + } + + for (var j = 0; j < boardKeys.length; j++) { + var key = boardKeys[j]; var board = boards[key]; if (board && $scope.colors.indexOf(board.color) !== -1) { - colorOccurrences.push(board.color); + colorOccurrences[$scope.colors.indexOf(board.color)]++; } } - colorOccurrences = colorOccurrences - .reduce(function (result, value) { - result[$scope.colors.indexOf(value)] = result[$scope.colors.indexOf(value)] + 1; - return result; - }, [0, 0, 0, 0, 0, 0]); - return $scope.colors[colorOccurrences.indexOf(Math.min.apply(Math, colorOccurrences))]; }