From 936aa7af0fee60abbb3fa0f4a83acce5a94ccd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 29 Jun 2019 15:33:40 +0200 Subject: [PATCH] Simplify adding rows to sortable tables The `append` method can handle arrays, so there's no need to loop through each element. There's more to improve on this method, like the `asc` variable being global to a table instead of depending on the current column, but for now I'm only refactoring and maintaining the current behaviour. --- app/assets/javascripts/table_sortable.js.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/table_sortable.js.coffee b/app/assets/javascripts/table_sortable.js.coffee index cc2b6adaa..4aab0e445 100644 --- a/app/assets/javascripts/table_sortable.js.coffee +++ b/app/assets/javascripts/table_sortable.js.coffee @@ -13,10 +13,10 @@ App.TableSortable = table = $(this).parents("table").eq(0) rows = table.find("tr:gt(0)").not("tfoot tr").toArray().sort(App.TableSortable.comparer($(this).index())) @asc = !@asc - if !@asc - rows = rows.reverse() - i = 0 - while i < rows.length - table.append rows[i] - i++ + + if @asc + table.append rows + else + table.append rows.reverse() + return