Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Simplify indexing arrays from the end with Array#at.
Anders Kaseorgc6b372b471b8
diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.jsindex 8609788c291..acb5c14cd32 100644--- a/frontend_tests/node_tests/narrow_local.js+++ b/frontend_tests/node_tests/narrow_local.js@@ -54,7 +54,7 @@ function test_with(fixture) {},last: () => {assert.notEqual(fixture.all_messages, undefined);- return fixture.all_messages[fixture.all_messages.length - 1];+ return fixture.all_messages.at(-1);},};diff --git a/frontend_tests/zjsunit/mdiff.js b/frontend_tests/zjsunit/mdiff.jsindex a588a0cd22b..46ab8385b34 100644--- a/frontend_tests/zjsunit/mdiff.js+++ b/frontend_tests/zjsunit/mdiff.js@@ -109,10 +109,7 @@ function diff_strings(string_0, string_1) {output_lines.push(line);} else if (line.startsWith("?")) {changes_list = parse_questionmark_line(line);- output_lines[output_lines.length - 1] = apply_color(- output_lines[output_lines.length - 1],- changes_list,- );+ output_lines.push(apply_color(output_lines.pop(), changes_list));} else {output_lines.push(line);}diff --git a/static/js/drafts.js b/static/js/drafts.jsindex 15b7ad13318..43d93fa2222 100644--- a/static/js/drafts.js+++ b/static/js/drafts.js@@ -470,7 +470,7 @@ function drafts_initialize_focus(event_name) {let draft_element;if (event_name === "up_arrow") {draft_element = document.querySelectorAll(- '[data-draft-id="' + draft_id_arrow[draft_id_arrow.length - 1] + '"]',+ '[data-draft-id="' + draft_id_arrow.at(-1) + '"]',);} else if (event_name === "down_arrow") {draft_element = document.querySelectorAll('[data-draft-id="' + draft_id_arrow[0] + '"]');@@ -565,7 +565,7 @@ export function drafts_handle_events(e, event_key) {if (document.activeElement.parentElement.hasAttribute("data-draft-id")) {restore_draft(focused_draft_id);} else {- const first_draft = draft_id_arrow[draft_id_arrow.length - 1];+ const first_draft = draft_id_arrow.at(-1);restore_draft(first_draft);}}diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.jsindex b2e1df07721..77a03eeace0 100644--- a/static/js/emoji_picker.js+++ b/static/js/emoji_picker.js@@ -563,7 +563,7 @@ export function emoji_select_tab(elt) {// Handles the corner case of the last category being// smaller than half of the emoji picker height.if (elt_height + scrolltop === scrollheight) {- currently_selected = section_head_offsets[section_head_offsets.length - 1].section;+ currently_selected = section_head_offsets.at(-1).section;}// Handles the corner case of the scrolling back to top.if (scrolltop === 0) {diff --git a/static/js/floating_recipient_bar.js b/static/js/floating_recipient_bar.jsindex a56161f4ed8..261a0d7ce2c 100644--- a/static/js/floating_recipient_bar.js+++ b/static/js/floating_recipient_bar.js@@ -85,7 +85,7 @@ export function first_visible_message(bar) {}// If none of the messages are visible, just take the last message.- return $(messages[messages.length - 1]);+ return messages.last();}export function get_date(elem) {diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex 1cd374d9355..849533e50d2 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -440,7 +440,7 @@ export function initialize(home_view_loaded) {// If we fall through here, we need to keep fetching more data, and// we'll call back to the function we're in.const messages = data.messages;- const latest_id = messages[messages.length - 1].id;+ const latest_id = messages.at(-1).id;load_messages({anchor: latest_id,diff --git a/static/js/message_list_data.js b/static/js/message_list_data.jsindex 865ab413d08..26f91c45017 100644--- a/static/js/message_list_data.js+++ b/static/js/message_list_data.js@@ -39,7 +39,7 @@ export class MessageListData {}last() {- return this._items[this._items.length - 1];+ return this._items.at(-1);}select_idx() {diff --git a/static/js/message_list_view.js b/static/js/message_list_view.jsindex de59ad72fa6..70543047ea4 100644--- a/static/js/message_list_view.js+++ b/static/js/message_list_view.js@@ -344,9 +344,7 @@ export class MessageListView {current_group,current_group.message_containers[0],);- current_group.message_containers[- current_group.message_containers.length - 1- ].include_footer = true;+ current_group.message_containers.at(-1).include_footer = true;new_message_groups.push(current_group);}};@@ -1212,7 +1210,7 @@ export class MessageListView {for (const message_container of message_containers) {if (current_group.length === 0 ||- same_recipient(current_group[current_group.length - 1], message_container)+ same_recipient(current_group.at(-1), message_container)) {current_group.push(message_container);} else {diff --git a/static/js/portico/integrations_dev_panel.js b/static/js/portico/integrations_dev_panel.jsindex d16dda2e02b..06b15861ee9 100644--- a/static/js/portico/integrations_dev_panel.js+++ b/static/js/portico/integrations_dev_panel.js@@ -74,8 +74,7 @@ function get_selected_integration_name() {}function get_fixture_format(fixture_name) {- const pieces = fixture_name.split(".");- return pieces[pieces.length - 1];+ return fixture_name.split(".").at(-1);}function get_custom_http_headers() {diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.jsindex dd9675b3c10..94121189eec 100644--- a/static/js/search_suggestion.js+++ b/static/js/search_suggestion.js@@ -641,7 +641,6 @@ export function get_search_result(base_query, query) {}const person_suggestion_ops = ["sender", "pm-with", "from", "group-pm"];- const search_operators_len = search_operators.length;// Handle spaces in person name in new suggestions only. Checks if the last operator is 'search'// and the second last operator in search_operators is one out of person_suggestion_ops.@@ -650,11 +649,11 @@ export function get_search_result(base_query, query) {// is an email of a user, both of these operators remain unchanged. Otherwise search operator// will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}.if (- search_operators_len > 1 &&+ search_operators.length > 1 &&last.operator === "search" &&- person_suggestion_ops.includes(search_operators[search_operators_len - 2].operator)+ person_suggestion_ops.includes(search_operators.at(-2).operator)) {- const person_op = search_operators[search_operators_len - 2];+ const person_op = search_operators.at(-2);if (!people.reply_to_to_user_ids_string(person_op.operand)) {last = {operator: person_op.operator,@@ -662,11 +661,11 @@ export function get_search_result(base_query, query) {negated: person_op.negated,};if (page_params.search_pills_enabled) {- all_operators[all_operators.length - 2] = last;- all_operators.splice(-1, 1);+ all_operators.splice(-2);+ all_operators.push(last);}- search_operators[search_operators_len - 2] = last;- search_operators.splice(-1, 1);+ search_operators.splice(-2);+ search_operators.push(last);}}diff --git a/static/js/stats/stats.js b/static/js/stats/stats.jsindex 0aa7d15555c..3337b80f446 100644--- a/static/js/stats/stats.js+++ b/static/js/stats/stats.js@@ -73,7 +73,7 @@ function update_last_full_update(end_times) {return;}- last_full_update = Math.min(last_full_update, end_times[end_times.length - 1]);+ last_full_update = Math.min(last_full_update, end_times.at(-1));const update_time = new Date(last_full_update * 1000);const locale_date = update_time.toLocaleDateString("en-US", {year: "numeric",@@ -253,7 +253,7 @@ function populate_messages_sent_over_time(data) {dates,values,last_value_is_partial: !is_boundary(- new Date(start_dates[start_dates.length - 1].getTime() + 60 * 60 * 1000),+ new Date(start_dates.at(-1).getTime() + 60 * 60 * 1000),),};}@@ -386,7 +386,7 @@ function compute_summary_chart_data(time_series_data, num_steps, labels_) {}let sum = 0;for (let i = 1; i <= num_steps; i += 1) {- sum += array[array.length - i];+ sum += array.at(-i);}data.set(key, sum);}@@ -939,7 +939,7 @@ function populate_messages_read_over_time(data) {dates,values,last_value_is_partial: !is_boundary(- new Date(start_dates[start_dates.length - 1].getTime() + 60 * 60 * 1000),+ new Date(start_dates.at(-1).getTime() + 60 * 60 * 1000),),};}diff --git a/static/js/upload.js b/static/js/upload.jsindex 50f5dd9dfc5..f52455ca7ca 100644--- a/static/js/upload.js+++ b/static/js/upload.js@@ -242,7 +242,7 @@ export function setup_upload(config) {return;}const split_uri = uri.split("/");- const filename = split_uri[split_uri.length - 1];+ const filename = split_uri.at(-1);if (config.mode === "compose" && !compose_state.composing()) {compose_actions.start("stream");}diff --git a/static/shared/js/fenced_code.js b/static/shared/js/fenced_code.jsindex c1a915335b1..e8c64e97bb9 100644--- a/static/shared/js/fenced_code.js+++ b/static/shared/js/fenced_code.js@@ -209,18 +209,18 @@ export function process_fenced_code(content) {handler_stack.push(current_handler);for (const line of input) {- const handler = handler_stack[handler_stack.length - 1];+ const handler = handler_stack.at(-1);handler.handle_line(line);}// Clean up all trailing blocks by letting them// insert closing fenceswhile (handler_stack.length !== 0) {- const handler = handler_stack[handler_stack.length - 1];+ const handler = handler_stack.at(-1);handler.done();}- if (output.length > 2 && output[output.length - 2] !== "") {+ if (output.length > 2 && output.at(-2) !== "") {output.push("");}