From f44e616a4b0725090c06f237c207b4853fff0892 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 17 Nov 2012 13:57:06 -0300 Subject: [PATCH] Minor fix. --- .../main/javascript/commands/DeleteCommand.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mindplot/src/main/javascript/commands/DeleteCommand.js b/mindplot/src/main/javascript/commands/DeleteCommand.js index b05cb677..31637d2c 100644 --- a/mindplot/src/main/javascript/commands/DeleteCommand.js +++ b/mindplot/src/main/javascript/commands/DeleteCommand.js @@ -150,17 +150,20 @@ mindplot.commands.DeleteCommand = new Class({ }, this); result.append(rels.flatten()); - // Filter for unique ... - result = result.sort(function (a, b) { - return a.getModel().getId() - b.getModel().getId(); - }); - var ret = [result[0]]; - for (var i = 1; i < result.length; i++) { // start loop at 1 as element 0 can never be a duplicate - if (result[i - 1] !== result[i] && result[i] != null) { - ret.push(result[i]); + if (result.length > 0) { + // Filter for unique ... + result = result.sort(function (a, b) { + return a.getModel().getId() - b.getModel().getId(); + }); + var ret = [result[0]]; + for (var i = 1; i < result.length; i++) { // start loop at 1 as element 0 can never be a duplicate + if (result[i - 1] !== result[i]) { + ret.push(result[i]); + } } + result = ret; } - return ret; + return result; } }); \ No newline at end of file