settings_profile_fields: Simplify convoluted sort algorithm to max.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-07-27 10:06:13 -07:00
committed by Tim Abbott
parent ec25baa344
commit d91d6d1fd1

View File

@@ -171,18 +171,11 @@ export function update_choice_delete_btn($container, display_flag) {
}
export function get_value_for_new_option(container) {
const $choice_rows = $(container).find(".choice-row");
if ($choice_rows.length === 0) {
// Value for the first option is 0.
return 0;
let value = 0;
for (const row of $(container).find(".choice-row")) {
value = Math.max(value, Number.parseInt($(row).attr("data-value"), 10) + 1);
}
const existing_option_values = [];
$choice_rows.each(function () {
existing_option_values.push(Number.parseInt($(this).attr("data-value"), 10));
});
existing_option_values.sort((a, b) => a - b);
return existing_option_values.at(-1) + 1;
return value;
}
function create_choice_row(container) {