From 6ab213921932d904c64c8b37a327a971a3c46cfc Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 26 Jan 2022 19:36:38 +0000 Subject: Replaced a confusing for loop with something that is (hopefully) easier to read and explicitly inverts start_index and end_index when the former is greater than the latter --- wqflask/wqflask/static/new/javascript/search_results.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/static/new/javascript/search_results.js b/wqflask/wqflask/static/new/javascript/search_results.js index 7124151e..a665e3d2 100644 --- a/wqflask/wqflask/static/new/javascript/search_results.js +++ b/wqflask/wqflask/static/new/javascript/search_results.js @@ -102,7 +102,13 @@ $(function() { try { start_index = parseInt(index_set.split("-")[0]); end_index = parseInt(index_set.split("-")[1]); - for (index = _j = start_index; start_index <= end_index ? _j <= end_index : _j >= end_index; index = start_index <= end_index ? ++_j : --_j) { + + // If start index is higher than end index (for example is the string "10-5" exists) swap values so it'll be interpreted as "5-10" instead + if (start_index > end_index) { + [start_index, end_index] = [end_index, start_index] + } + + for (index = start_index; index <= end_index; index++) { index_list.push(index); } } catch (_error) { -- cgit v1.2.3