From b9dd4a14c94461735071c6b2af2ecbe5c75c0e7f Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 6 Oct 2023 14:24:14 +0000 Subject: [PATCH] hello: Write better variable names. --- web/src/portico/hello.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/web/src/portico/hello.js b/web/src/portico/hello.js index ac64d3211d..ae761f21e0 100644 --- a/web/src/portico/hello.js +++ b/web/src/portico/hello.js @@ -1,16 +1,16 @@ // Mark this as a module for ESLint and Webpack. export {}; -function get_new_rand(oldRand, max) { - const newRand = Math.floor(Math.random() * max); - return newRand === oldRand ? get_new_rand(newRand, max) : newRand; +function get_new_rand(old_random_int, max) { + const random_int = Math.floor(Math.random() * max); + return random_int === old_random_int ? get_new_rand(random_int, max) : random_int; } function get_random_item_from_array(array) { return array[Math.floor(Math.random() * array.length)]; } -const current_clint_logo_class_names = new Set([ +const current_client_logo_class_names = new Set([ "client-logos__logo_akamai", "client-logos__logo_tum", "client-logos__logo_wikimedia", @@ -18,7 +18,7 @@ const current_clint_logo_class_names = new Set([ "client-logos__logo_dr_on_demand", "client-logos__logo_maria", ]); -const future_logo_class_names = new Set([ +const future_client_logo_class_names = new Set([ "client-logos__logo_pilot", "client-logos__logo_recurse", "client-logos__logo_level_up", @@ -29,26 +29,28 @@ const future_logo_class_names = new Set([ "client-logos__logo_lean", "client-logos__logo_asciidoc", ]); -let current_clint_logo_class_namesIndex = 0; +let current_client_logo_class_names_index = 0; function update_client_logo() { if (document.hidden) { return; } - const logos = [...document.querySelectorAll("[class^='client-logos__']")]; - current_clint_logo_class_namesIndex = get_new_rand( - current_clint_logo_class_namesIndex, - logos.length, + const client_logos = [...document.querySelectorAll("[class^='client-logos__']")]; + current_client_logo_class_names_index = get_new_rand( + current_client_logo_class_names_index, + client_logos.length, ); - const el = logos[current_clint_logo_class_namesIndex]; + const client_logo_elt = client_logos[current_client_logo_class_names_index]; - const oldClass = el.className; - el.className = ""; - current_clint_logo_class_names.delete(oldClass); - const newClass = get_random_item_from_array([...future_logo_class_names.values()]); - future_logo_class_names.delete(newClass); - el.className = newClass; - current_clint_logo_class_names.add(newClass); - future_logo_class_names.add(oldClass); + const current_logo_class = client_logo_elt.className; + current_client_logo_class_names.delete(current_logo_class); + + const next_logo_class = get_random_item_from_array([ + ...future_client_logo_class_names.values(), + ]); + future_client_logo_class_names.delete(next_logo_class); + client_logo_elt.className = next_logo_class; + current_client_logo_class_names.add(next_logo_class); + future_client_logo_class_names.add(current_logo_class); } setInterval(update_client_logo, 2500);