<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Becca Jonas on Medium]]></title>
        <description><![CDATA[Stories by Becca Jonas on Medium]]></description>
        <link>https://medium.com/@beccajonas3?source=rss-1d3687745f11------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lhwqTdgE3wfzkc11ZyuByw.png</url>
            <title>Stories by Becca Jonas on Medium</title>
            <link>https://medium.com/@beccajonas3?source=rss-1d3687745f11------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:01:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@beccajonas3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NeetCode 75: Arrays and Hashing]]></title>
            <link>https://medium.com/@beccajonas3/neetcode-75-arrays-and-hashing-c215f1f750a5?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/c215f1f750a5</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[neetcode]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Wed, 28 Feb 2024 16:57:04 GMT</pubDate>
            <atom:updated>2024-02-28T16:57:04.570Z</atom:updated>
            <content:encoded><![CDATA[<h4>Explaining Contains Duplicates, Valid Anagram, Two Sum</h4><blockquote><a href="https://neetcode.io/practice">NeetCode Blind 75</a> is a popular list of algorithm practice problems. It was suggested to me by a bootcamp instructor for interview prep. I’m breaking down the solutions to these questions in this blog series! Follow along and let’s study together.</blockquote><figure><img alt="Hand stamp with “DUPLICTATED” stamped onto a white background in red ink with text graphic writing: “LeetCode #217: Find Duplicates”" src="https://cdn-images-1.medium.com/max/1024/1*HpLjVT2ZHHw2IXeD1anANA.png" /></figure><h3>Contains Duplicates (LeetCode #217)</h3><p>Given an integer array nums, return true if any value appears <strong>at least twice</strong> in the array, and return false if every element is distinct.</p><p><strong>Approach:</strong></p><p>We will utilize the Python set data structure to efficiently checks for duplicates. <a href="https://www.w3schools.com/python/python_sets.asp">Sets</a> are collections of unique elements, meaning they automatically eliminate any duplicates that are added to them.</p><p>By leveraging this property, we can iteratively examine each element in the list and add it to a set. If an element is already in the set, we know it’s a duplicate, and we can return True. If we complete the loop without finding any duplicates, we return False.</p><p><strong>Solution:</strong></p><pre>class Solution:<br>    def containsDuplicate(self, nums: List[int]) -&gt; bool:<br>        # Initialize empty set to store unique elements<br>        hashset = set()<br><br>      # Iterate through each element in the list, check if element is in set<br>        for n in nums:<br>            if n in hashset:<br>                return True<br>            hashset.add(n) <br>        return False</pre><p><strong>Explanation:</strong></p><ol><li>We initialize an empty set() called hashset to store unique elements.</li></ol><p>2. We iterate through each element n in the input list nums.</p><p>3. For each element n, we check if it’s already in the hashset. If it is, we return True, indicating the presence of a duplicate.</p><p>4. If n is not in the hashset, we add it to the set using the add() method.</p><p>5. Once the loop completes, without encountering any duplicates, we return False, indicating that there are no duplicates in the list.</p><p><strong>Time and Space Complexity:</strong></p><p>The solution has a time complexity of <em>O(n)</em>, where <em>n</em> represents the number of elements in the input list nums. It achieves this by iterating through each element precisely once and utilizing set operations to check for membership and adding elements, which typically have constant time complexity.</p><p>The space complexity is <em>O(n)</em>, as hashset may store all elements from the input list in the worst-case scenario. Despite potential growth in memory usage, the solution remains practical and memory-efficient, making it suitable for handling large datasets.</p><figure><img alt="Small wooden tiles with black letters capitalized on them with text graphic writing: “LeetCode #242: Valid Anagram”" src="https://cdn-images-1.medium.com/max/1024/1*9xSjh5KC09IkpJTjmykDrw.png" /></figure><h3>Valid Anagram (LeetCode #242)</h3><p>Given two strings s and t, return true if t is an anagram of s, and false otherwise.</p><p><strong>Approach:</strong></p><p>We can approach this problem by counting the occurrences of each character in both strings and comparing the counts. If the counts of characters in both strings are identical, the strings are anagrams of each other. Otherwise, they are not.</p><p>We will utilize hashmaps to keep the count of each element of each string as we iterate through.</p><p><strong>Solution:</strong></p><pre>class Solution:<br>    def isAnagram(self, s: str, t: str) -&gt; bool:<br>        # Check if the lengths of the strings are different<br>        if len(s) != len(t):<br>            return False<br><br>        # Create dictionaries to store character counts for each string<br>        s_count = {}<br>        t_count = {}<br><br>        # Count occurrences of characters in the first string<br>        for char in s:<br>            if char in s_count:<br>                s_count[char] += 1<br>            else:<br>                s_count[char] = 1<br>        <br>        # Count occurrences of characters in the second string<br>        for char in t:<br>            if char in t_count:<br>                t_count[char] += 1<br>            else:<br>                t_count[char] = 1<br><br>        # Compare the character counts of both strings<br>        if s_count == t_count:<br>            return True<br>        else:<br>            return False</pre><p><strong>Explanation:</strong></p><ol><li>We begin by checking if the lengths of the input strings s and t are different. If they are not of equal length, they cannot be anagrams, so we return False.</li><li>Next, we create two dictionaries, s_count and t_count, to store the counts of characters in each string.</li><li>We iterate through each character in the first string s and update its count in the s_count dictionary.</li><li>Similarly, we iterate through each character in the second string t and update its count in the t_count dictionary.</li><li>Finally, we compare the character counts of both strings. If the dictionaries s_count and t_count are equal, we return True, indicating that the strings are anagrams. Otherwise, we return False.</li></ol><p><strong>Time and Space Complexity:</strong></p><p>The solution has a time complexity of <em>O(n)</em>, where <em>n</em> represents the t and s strings combined. We achieve this by iterating through each character in both strings once to count their occurrences.</p><p>The space complexity is <em>O(n)</em>, as both hashmaps, t_count and s_count store only the counts of character in each string. In the worst-case scenario where there are no repeated characters, both hashmaps could potentially store all the unique characters from both strings, leading to a proportional growth in space usage relative to the input string size.</p><figure><img alt="Calculator on light blue background with text graphic writing: “LeetCode #1: Two Sum”" src="https://cdn-images-1.medium.com/max/1024/1*HxRc2JJl7cpQrOCcEmuVtw.png" /></figure><h3>Two Sum (LeetCode #1)</h3><p>Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice.</p><p><strong>Approach:</strong></p><p>We will utilize a hashmap to add each value and its corresponding index as we iterate through the list of numbers. Before adding a new value and its index into the hashmap, we will check and see if the difference between the target and the current value exists in the hashmap.</p><p>If the difference exists, we will return the index of the current value and the index of the difference value in the hashmap.</p><p><strong>Solution:</strong></p><pre>class Solution:<br>    def twoSum(self, nums: List[int], target: int) -&gt; List[int]:<br>        prevMap = {} # value : index<br><br>        for i, n in enumerate(nums):<br>            diff = target - n<br>            if diff in prevMap:<br>                return [prevMap[diff], i]<br>            prevMap[n] = i</pre><p><strong>Explanation:</strong></p><ol><li>We initialize an empty dictionary prevMap, which will serve as our hashmap data structure to store previously seen numbers and their corresponding indices.</li><li>We iterate through the elements of the input list nums using the <a href="https://www.geeksforgeeks.org/enumerate-in-python/">enumerate function.</a> This function provides both the index i and the value n of each element in the list.</li><li>For each element n, we calculate the difference diff between the target value and the current element. This difference represents the value we need to find in the array to reach the target sum.</li><li>We then check if the calculated diff exists in our prevMap. If it does, it means we have found the complementary number that, when added to the current element, results in the target sum. In this case, we return the indices of the complementary number prevMap[diff] and the current element i.</li><li>If the diff is not found in prevMap, we store the current element n along with its index i in the dictionary prevMap. This allows us to keep track of previously seen numbers as we iterate through the list.</li><li>If no such pair of numbers is found that adds up to the target sum, the function returns an empty list, indicating that no solution exists.</li></ol><p><strong>Time and Space Complexity:</strong></p><p>The time complexity of the solution is <em>O(n)</em>, where <em>n</em> represents the number of elements in the input list nums. This linear time complexity arises from the single iteration through the elements of the list. Within each iteration, the dictionary lookup to check for the existence of the difference diff has a constant time complexity on average, thanks to the efficient hashing implemented in Python dictionaries.</p><p>The space complexity of the solution is also <em>O(n)</em>. It utilizes a dictionary prevMap to store previously encountered numbers and their indices. In the worst-case scenario, where all elements of the input list are distinct and none of the pairs sum up to the target value, the dictionary may store all the elements of the input list along with their indices. Consequently, the space required by the dictionary grows proportionally with the size of the input list.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c215f1f750a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Accessibility For Beginners Pt. 2]]></title>
            <link>https://medium.com/@beccajonas3/web-accessibility-for-beginners-pt-2-0f0f8586bc12?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f0f8586bc12</guid>
            <category><![CDATA[web-accessibility]]></category>
            <category><![CDATA[accessbility]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 23:06:12 GMT</pubDate>
            <atom:updated>2024-02-13T23:06:12.488Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Computer keyboard with three blue keys showing a physical, visual and hearing impairment symbols." src="https://cdn-images-1.medium.com/max/1024/1*ukSbc5K2EHPoCncm13AQdA.png" /></figure><p>The internet is for everyone, and it’s our responsibility as web developers to make sure everyone can experience what it has to offer.</p><p>Welcome to part two of of my blog series. Through bite-sized pieces of advice, even beginners can integrate accessibility principles into their learning and projects. By doing so, they can establish a robust foundation to carry forward into their future endeavors.</p><h3>Text Alternatives</h3><p>Multimedia content, such as images and videos, can pose accessibility challenges for visually-impaired and hearing-impaired users without proper handling by the developer.</p><p>You can make images more accessible by providing a meaningful alt text in &lt;img&gt; elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0pR--8IMhbbj206d4SveA.png" /></figure><p>In the image above the top code for the image of the cupcake reads:</p><pre>&lt;div class=&quot;image&quot;&gt;<br> &lt;img src=&quot;cupcake.jpg&quot; alt=&quot;imgage of cupake&quot; /&gt;<br>&lt;/div&gt;</pre><p>This is how NOT to do alt text. First there is a spelling error. This can confuse readers/listeners. Second, the code says “image of” which is unnecessary as the image tag tells screen readers that it is an image.</p><p>The correct code would be something like the following.</p><pre>&lt;div class=&quot;image&quot;&gt;<br> &lt;img src=&quot;cupcake.jpg&quot; alt=&quot;Vanilla cupcake topped with pink frosting and multicolored sprinkles.&quot; /&gt;<br>&lt;/div&gt;</pre><p>This alt text description is succinct, specific and emphasizes key details that convey the image to the user who would be reading or listening to the description.</p><h3>2. Color Usage</h3><p>Depending solely on color to convey information risks excluding visually impaired users who may not discern certain colors. Since screen readers do not relay color information, it’s crucial to offer adequate context for conveying the intended message.</p><p>An example highlighting this challenge is with required fields in forms. Instead of solely using red outlines to signify required fields, it’s essential to complement color cues with additional indicators like a red asterisk (*) or a label explicitly stating “required.” This ensures accessibility for all users.</p><h3>3. Link Labeling Techniques</h3><p>In the case below, the developer has decided to embed a link behind the [Read more...] text. This is common practice and again, is <em>unintentionally</em> excluding users from receiving the full context of the link.</p><pre>&lt;h4&gt;Big News! &lt;/h4&gt;<br>&lt;p&gt; A new cupcake shop is set to open, offering a variety of delicious flavors and treats.<br>  &lt;a href=&quot;cupcakes..com&quot;&gt;[Read more...]&lt;/a&gt;<br>&lt;/p&gt;</pre><p>Developers can make a simple adjustment to provide this context using an aria-label. Offering a descriptive text label enables users to differentiate the link from others on the webpage, aiding them in deciding whether to navigate to the linked destination. See the example below:</p><pre>&lt;h4&gt;Big News!&lt;/h4&gt;<br>&lt;p&gt; A new cupcake shop is set to open, offering a variety of delicious flavors and treats.<br>  &lt;a href=&quot;cupcakes.com&quot; aria-label=&quot;Read more about the new cupcake shop&quot;&gt;[Read more...]&lt;/a&gt;<br>&lt;/p&gt;</pre><p>Notice how the aria-label begins with the same text that is used within the link, “Read more.” This is recommended to allow consistent communication between users.</p><p>Feel free to follow along as I dive into more web accessibility tips. I used the following resources to write this blog. Check them out for more info!</p><p><a href="https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA8.html">WCAG 2.2 Techniques: Using aria-label for link purpose</a></p><p><a href="https://webaim.org/techniques/forms/#keyboard">Web AIM: Creating Accessible Forms</a></p><p><a href="https://www.ignitingbusiness.com/blog/6-alt-text-alt-tag-writing-tips-to-benefit-readers-and-seo">6 Alt Text (Alt Tag) Writing Tips to Benefit Readers and SEO</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f0f8586bc12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Accessibility For Beginners Pt. 1]]></title>
            <link>https://medium.com/@beccajonas3/web-accessibility-for-beginners-19ffe948832a?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/19ffe948832a</guid>
            <category><![CDATA[web-accessibility]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 19:54:13 GMT</pubDate>
            <atom:updated>2024-02-13T23:38:12.611Z</atom:updated>
            <content:encoded><![CDATA[<p>Curious how to be an accessibility-minded web developer? Me too! Let’s learn together.</p><figure><img alt="Quote from Steve Krug on blue backgorund: “How many opportunities do we have to dramatically improve people’s lives just by doing our job a little better?”" src="https://cdn-images-1.medium.com/max/1024/1*HQlWI17FaFgV6cbZSC171Q.png" /></figure><p><em>“The one argument for accessibility that doesn’t get made nearly often enough is how extraordinarily better it makes some people’s lives. </em><strong><em>How many opportunities do we have to dramatically improve people’s lives just by doing our job a little better?” </em></strong><em>― Steve Krug</em></p><p>As developers, it’s our responsibility to drive progress forward. Amidst the ongoing cycle of building, breaking, maintaining, and recreating code, one crucial aspect that should never be overlooked is accessibility. After all, the internet is for everyone.</p><p>With this in mind, I’ve started this blog series aimed at promoting web accessibility. Through bite-sized pieces of advice, even beginners can integrate accessibility principles into their learning and projects. By doing so, they can establish a robust foundation to carry forward into their future endeavors.</p><h3>1. Color Contrast</h3><p>When designing, having good color contrast can help users with visual impairments consume your content easier. This is an easy adaptation that devs can apply to their work.</p><p>The <a href="https://www.w3.org/TR/WCAG20/">Web Content Accessibility Guidelines</a> (WCAG) approves of a 4.5:1 contrast ratio for normal text and 3:1 for larger text. If you aren’t a color theory expert, a great tool to use to see if your color scheme meets Web Content Accessibility Guidelines (WCAG) is the <a href="https://webaim.org/resources/contrastchecker/">Web Aim Contrast Checker.</a></p><figure><img alt="Web AIM Contrast Checker interface. Shows an example of white text on red background that does not meet the Web Content Accessibility Guidelines text contrast standard with a Contrast Ratio of 1.76 to 1." src="https://cdn-images-1.medium.com/max/1024/1*0qQwz-M_CJs1odZnSwwZRg.png" /></figure><figure><img alt="Web AIM Contrast Checker interface. Shows an example of white text on red background that meets the Web Content Accessibiltiy Guidelines text contrast standard with a Contrast Ratio of 7.32 to 1." src="https://cdn-images-1.medium.com/max/1024/1*FYUKh-0BScWoGpdnNHU1Ug.png" /></figure><p>When you visit the website, you have the ability to pick a foreground and background color as well as the luminance. As you adjust the colors, you can see the Contrast Ratio your color combination holds and whether or not they pass the WCAG.</p><h3>2. Use Clear Language</h3><p>Go back to my last section. Notice how I typed out Web Content Accessibility Guidelines before referring to it as WCAG? That was intentional. As developers, we can adopt simple linguistic adjustments to improve accessibility.</p><p>For example, it’s beneficial to use abbreviations only after initially presenting the expanded term a few times. In code, employing HTML elements like &lt;abbr&gt; to define acronyms enhances clarity, ensuring accessibility for all users.</p><p>Instead of expressing ranges as “1–4,” opting for “1 to 4” promotes straightforward comprehension, minimizing potential confusion for screen reader users. Similarly, while native English speakers may easily understand abbreviations like “Feb.,” in the context of a date, it’s advisable to spell them out for clarity to cater to users of all ages and backgrounds.</p><p>Though seemingly minor, these linguistic considerations can significantly enhance the user experience. By embracing such practices, developers have the opportunity to positively impact users’ lives through incremental improvements in accessibility.</p><h3>3. Mouse-Specific Events</h3><p>JavaScript offers a plethora of user events, which are a developer’s dream but can present challenges for screen reader users. Certain events, such as mouseover, mouseout, and double click, pose accessibility issues as they are tailored for mouse interactions.</p><p>This can be problematic for individuals relying on keyboard controls for web navigation, leading to potential difficulties in accessing functionalities triggered by these events.</p><p>To address this issue, developers should implement device-independent event handlers alongside mouse-specific events. For instance, incorporating focus and blur events provides accessibility for keyboard users, ensuring that interactive elements remain operable across various input methods.</p><pre>var button = document.getElementById(&quot;myButton&quot;);<br><br>// Adding mouse-specific event listeners<br>  button.addEventListener(&quot;mouseover&quot;, handleMouseOver);<br>  button.addEventListener(&quot;mouseout&quot;, handleMouseOut);<br><br>// Adding device-independent event listeners<br>  button.addEventListener(&quot;focus&quot;, handleMouseOver);<br>  button.addEventListener(&quot;blur&quot;, handleMouseOut);</pre><p>In the example above, when the button receives focus (via keyboard navigation), it triggers the same functionality as the mouseover event, and when it loses focus, it triggers the mouseout event, ensuring consistent behavior across different input methods.</p><p>This approach enhances the inclusivity of web applications, enabling seamless interaction for all users regardless of their preferred input device.</p><p>Feel free to follow along as I dive into more web accessbility tips. I used the following resources to write this blog. Check them out for more info!</p><p><a href="https://www.w3.org/TR/WCAG20/">Web Content Accessibility Guidelines (WCAG) 2.0</a></p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Accessibility/CSS_and_JavaScript#color_and_color_contrast">MDN Web Docs: CSS and JavaScript accessibility best practices.</a></p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Accessibility/HTML">MDN Web Docs: HTML: A good basis for accessibility</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19ffe948832a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scoring Cribbage Hands with Python’s Itertools]]></title>
            <link>https://medium.com/@beccajonas3/scoring-cribbage-hands-with-pythons-itertools-ef4d225c0533?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef4d225c0533</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Sat, 06 Jan 2024 23:24:14 GMT</pubDate>
            <atom:updated>2024-01-06T23:24:14.187Z</atom:updated>
            <content:encoded><![CDATA[<p>Cribbage is a classic card game known for its intricate, and somewhat trivial scoring system. Mastering it involves not just strategic play but also an understanding of potential scoring combinations in your hand.</p><p>I built a CLI version of cribbage using Python. Without <a href="https://docs.python.org/3/library/itertools.html#itertools.permutations">Python’s itertools,</a> writing the logic for scoring a hand would’ve been a nested-loop nightmare.</p><figure><img alt="Cribbage board and cards" src="https://cdn-images-1.medium.com/max/1024/1*dPKmVylrjtFWiQbGPUc0xQ.png" /></figure><p>In my version of cribbage, I created a Scoring class that encapsulates the logic for evaluating different combinations of cards. Let&#39;s delve into the itertools I used.</p><h3>.combinations()</h3><pre>def check_for_15s(self, card_list):<br>        points = 0<br><br>        for subset_size in range(1, len(card_list) + 1):<br>            for subset in itertools.combinations(card_list, subset_size):<br>                subset_expression = &quot; + &quot;.join(f&quot;{card.value} {card.suit}&quot; for card in subset)<br><br>                if sum(card.points for card in subset) == 15:<br>                    print(f&quot;{subset_expression} = 15.&quot;)<br>                    points += 2</pre><p>The check_for_15s method utilizes itertools.combinations() to generate all possible subsets of cards and checks if the sum of their point values equal 15. combinations()do not consider the order of elements and generates all possible combinations of the input iterable.</p><p>The combinations()method takes the input iterable, in this case card_list , and the desired length of tuples that gets evaluated. In this scenario, the subset_size is every possible length of combinations of the card list.</p><p>sum(card.points for card in subset) calculates the sum of point values for the current subset and checks if it equals 15. If the sum is 15, it prints the combination and increments the total score (points) by 2.</p><p>Here’s another example of combinations():</p><pre>def check_for_pairs(self, card_list):<br>        points = 0<br><br>        for card1, card2 in itertools.combinations(card_list, 2):<br>            if card1.value == card2.value:<br>                print(f&quot;{card1} and {card2} are pairs.&quot;)<br>                points += 2<br><br>        return points</pre><p>This time, itertools.combinations() takes in the card_list and sets the length of the tuples to be 2. Similar to the check_for_15s method, the check_for_pairs function evaluates combinations, but in this case, it focuses on pairs of cards. It prints the pairs found and awards 2 points for each matching pair in the card_list.</p><h3>.permutations()</h3><pre>def check_for_3_card_runs(self, card_list):<br>    points = 0<br><br>    allowed_values = [&quot;A&quot;, 2, 3, 4, 5, 6, 7, 8, 9, 10, &quot;J&quot;, &quot;Q&quot;, &quot;K&quot;]<br><br>    for three_card_combo in itertools.permutations(card_list, 3):<br>        values = [card.value for card in three_card_combo]<br>        indices = [allowed_values.index(value) for value in values]<br><br>        if all(indices[i] == indices[i + 1] - 1 for i in range(len(indices) - 1)):<br>            print(f&quot;{&#39; &#39;.join(str(card) for card in three_card_combo)} for a three-card run.&quot;)<br>            points += 3<br><br>    return points</pre><p>In the check_for_3_card_runs method, I used itertools.permutations() to generate all conceivable 3-card combinations. This was done to assess whether these combinations could be categorized as runs, earning 3 points in the game of cribbage. I specified the length of the tuples to be 3 by providing it as an argument in the method.</p><p>For each generated three-card combination, I extract the values of the cards using values = [card.value for card in three_card_combo]. I then map these values to their corresponding indices in the allowed_values list to ensure the values form a consecutive run.</p><p>For example, if the values list of the combination is [&#39;4&#39;, &#39;5&#39;, &#39;6&#39;], due to the allowed_values being[&quot;A&quot;, 2, 3, 4, 5, 6, 7, 8, 9, 10, &quot;J&quot;, &quot;Q&quot;, &quot;K&quot;], the indices list will be [3, 4, 5], representing the indices of &#39;4&#39;, &#39;5&#39;, and &#39;6&#39; in the allowed_values list.</p><p>Utilizing Python’s itertools module greatly facilitates the implementation of a sophisticated scoring system for Cribbage hands. By leveraging the power of combinations() and permutations(), we can explore all possible combinations of cards, making the intricate scoring logic of Cribbage more manageable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef4d225c0533" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React useEffect: Understanding the dependency array]]></title>
            <link>https://medium.com/@beccajonas3/react-useeffect-understanding-the-dependency-array-c43319f69e9e?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/c43319f69e9e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 18:43:48 GMT</pubDate>
            <atom:updated>2023-12-08T18:48:08.721Z</atom:updated>
            <content:encoded><![CDATA[<p>The <em>main effect</em> of a React component is to return our written JSX code and render that code within our app. To enhance the interactivity and sophistication of a React application, the inclusion of <em>side effects</em> becomes equally important.</p><p>Enter the useEffect hook.</p><p>useEffect is a powerful tool for handling asynchronous operations such as fetching data or setting timers. By incorporating useEffect, developers gain a streamlined way to integrate these functionalities into their React applications.</p><p>In this blog, I want to talk specifically about the second half of the useEffect hook, the dependency array.</p><figure><img alt="Screen shot of tweet" src="https://cdn-images-1.medium.com/max/1024/1*MIM4r9JVml-XXEiaEcraLw.png" /></figure><p>When I came across the photo above in my Flatiron School course materials, my understanding of useEffect and its power became clear.</p><p>Let’s break it down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4X7F5hz6dPKJEpiV-4YKg.png" /></figure><p>An empty dependency array ([]) causes the code within the effect to run when the component is rendered. It runs upon the initial mount, and does not depend on anything else that would trigger it again.</p><p>This is useful when we have side effects that are independent of any variables derived from the component&#39;s state or props.</p><pre>import React, { useState, useEffect } from &quot;react&quot;;<br><br>function Contacts() {<br>  const [contactList, setContactList] = useState([]);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;https://localhost:3000/contacts&#39;)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setContactList(data))<br>  }, []);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Contacts&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {contactList.map(contact =&gt; (<br>          &lt;li key={contact.id}&gt;{contact.name}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Contacts;</pre><p>In the example above, by using an empty dependency array, you ensure that this fetch operation, and subsequent setContactList function, happens once.</p><p>The empty array prevents unnecessary API calls, optimizing performance. The useEffect is not in sync with any variable that exists in our React app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WpkpSnxkeodRQwCJgV6KA.png" /></figure><p>Adding a variable to the dependency array triggers the code in our useEffect to run every time that variable is updated.</p><pre>import React, { useState, useEffect } from &quot;react&quot;;<br><br>function Contacts({ contactPhoto }) {<br>  const [contactList, setContactList] = useState([]);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;https://localhost:3000/contacts&#39;)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setContactList(data))<br>  }, [contactPhoto]);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Contacts&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {contactList.map(contact =&gt; (<br>          &lt;li key={contact.id}&gt;{contact.name}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Contacts;</pre><p>In this scenario, the useEffect is triggered each time the contactPhoto prop gets updated.</p><p>Envision a situation where users have the ability to modify their contact photo within our application through a PATCH request and in doing so, the contactPhoto state changes. This state variable is then passed down to the Contacts() component via props.</p><p>Within this component, the useEffect is responsible for rendering the list of contacts retrieved from the API. By setting the dependency array to include the contactPhoto variable ensures that whenever users update their contact photo via the PATCH request, the useEffect refetches data based on the newly modified photo.</p><p>The fetch maintains synchronization with the contactPhoto state, ensuring that the UI remains up-to-date with the latest contact photo changes.</p><p>Whether it’s about executing a side effect once with an empty dependency array or adjusting to prop changes, the useEffect hook, combined with careful dependency management, remains a fundamental tool for React developers, helping them build efficient applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c43319f69e9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Array Methods: find(), filter(), map(), reduce(),]]></title>
            <link>https://medium.com/@beccajonas3/array-methods-find-filter-map-reduce-b483b6562e5c?source=rss-1d3687745f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/b483b6562e5c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[Becca Jonas]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 23:51:04 GMT</pubDate>
            <atom:updated>2023-11-16T23:51:04.783Z</atom:updated>
            <content:encoded><![CDATA[<h3>Array Methods: find(), filter(), map(), reduce()</h3><h3>What’s An Array? Let’s Review.</h3><p>In JavaScript, an array is as an ordered collection of data stored under a single variable. Each element within an array is assigned to an index, starting at 0, indicating its position within the array.</p><pre>let sports = [<br>&quot;basketball&quot;, <br>&quot;tennis&quot;,<br>&quot;baseball&quot;,<br>&quot;football&quot;,<br>&quot;volleyball&quot;,<br>]<br><br>console.log(sports[0])<br>// &quot;basketball&quot;</pre><h3>Array Iteration Methods</h3><p>Array iteration is the process of looping through each element of an array. Javascript has built in methods with specific functionality to help us access, modify and utilize the data within a given array.</p><figure><img alt=".find() written in black with a yellow background." src="https://cdn-images-1.medium.com/max/1024/1*78nlKLoPP-0r3ILKW-FWQA.png" /></figure><p>find()</p><p>The find() method applies a callback function to each element in an array, in order, until the callback function returns a truthy value. The method then returns the element that triggered the truthy outcome.</p><pre>let sports = [<br>&quot;basketball&quot;, <br>&quot;tennis&quot;,<br>&quot;baseball&quot;,<br>&quot;football&quot;,<br>&quot;volleyball&quot;,<br>]<br><br>let bSport = sports.find(sport =&gt; sport.charAt(0).toLowerCase() === &quot;b&quot;);<br>// bSport = &quot;basketball&quot;</pre><p>Notice that the return value is only &#39;basketball&#39; even though there are two sports that start with the letter “b.” This is because find() will stop iterating once the condition in the callback function is met and return that value.</p><figure><img alt=".filter() written in black with a yellow background." src="https://cdn-images-1.medium.com/max/1024/1*Had70Mmi2UvxMQv24vBayw.png" /></figure><p>filter()</p><p>The filter() method creates a new array with the values that meet a given condition. Imagine the method “filtering” through the data and pulling out a list of elements that meet the declared condition.</p><pre>let sports = [<br>&quot;basketball&quot;, <br>&quot;tennis&quot;,<br>&quot;baseball&quot;,<br>&quot;football&quot;,<br>&quot;volleyball&quot;,<br>]<br><br>let startsWithB = sports.filter(sport =&gt; sport.toLowerCase().startsWith(&quot;b&quot;));<br><br>// startsWithB = [&quot;basketball&quot;, &quot;baseball&quot;]</pre><p>In this example, we use the filter() method on the sports array to create a new array called startsWithB. The filter() method iterates through each element of sports and checks if the sport&#39;s name starts with the letter “b.”</p><p>The returned array contains all of the the values that meet this condition.</p><p><em>Beginners Tip: I find it helpful to use a plural word when declaring my array variable. When I use an array method, I then set the parameter as the singular version of that word.</em></p><p><em>When writing the code above, I say to myself, “Filter </em>sports<em>. Return each </em>sport<em> that starts with the letter ‘b.’” I’ve found that this helps keep my code clean and has improved my general understanding of iterating over arrays.</em></p><figure><img alt=".map() written in black with a yellow background." src="https://cdn-images-1.medium.com/max/1024/1*9t6aui-Hc7VWGirXfLBUQQ.png" /></figure><p>map()</p><p>The map() method creates a new array after modifying each element.</p><pre>let sports = [<br>&quot;basketball&quot;, <br>&quot;tennis&quot;,<br>&quot;baseball&quot;,<br>&quot;football&quot;,<br>&quot;volleyball&quot;,<br>]<br><br>let capitalizedSports = sports.map(sport =&gt; sport.charAt(0).toUpperCase() + sport.slice(1))<br><br>// capitalizedSports = [&quot;Basketball&quot;, &quot;Tennis&quot;, &quot;Baseball&quot;, &quot;Football&quot;, &quot;Volleyball&quot; ]</pre><p>In this example, we apply map() to the sports array to create a new array capitalizedSports. The first character of each string is capitalized using charAt(0).toUpperCase()then concatenated to the remainder of the word using slice(1).</p><p>Each value of the array gets modified and placed into the new array.</p><figure><img alt=".reduce() written in black with a yellow background." src="https://cdn-images-1.medium.com/max/1024/1*WKGoFecz7PMCHubpJm0I0w.png" /></figure><p>reduce()</p><p>The reduce() method creates a summary, aggregation or, most commonly, a sum of the values in an array. The method takes a reducing callback function on each element and accumulates them into a single value.</p><p>In example below, our sports array example now has five objects as its values. Each object has a sport and ticketPrice element.</p><pre>let sports = [<br>  {sport: &quot;basketball&quot;, ticketPrice: 10},<br>  {sport: &quot;tennis&quot;, ticketPrice: 8},<br>  {sport: &quot;baseball&quot;, ticketPrice: 7},<br>  {sport: &quot;football&quot;, ticketPrice: 10},<br>  {sport: &quot;volleyball&quot;, ticketPrice: 8},<br>];<br><br>let totalTicketPrice = sports.reduce((accumulator, currentSport) =&gt; {<br>  return accumulator + currentSport.ticketPrice;<br>}, 0);<br><br>// totalTicketPrice = 43<br><br>// iteration 1: 0 + 10 = 10<br>// iteration 2: 10 + 8 = 18<br>// iteration 3: 18 + 7 = 25<br>// iteration 4: 25 + 10 = 35<br>// iteration 5: 35 + 8 = 43</pre><p>The callback function within the reduce() method is structured with two parameters: accumulator and currentSport. Think of the accumulator as the scoreboard that accumulates the results throughout the iteration process. We initialize the accumulator with a value of 0 after the callback function.</p><p>The currentSport parameter signifies the single sport object within the array during each iteration of the loop.</p><figure><img alt="// iteration 1: 0 + 10 = 10 // iteration 2: 10 + 8 = 18 // iteration 3: 18 + 7 = 25 // iteration 4: 25 + 10 = 35 // iteration 5: 35 + 8 = 43" src="https://cdn-images-1.medium.com/max/1024/1*uuCux9pHE_83MfD_lYjBVQ.png" /></figure><p>The callback function accumulates the sum as the iteration progresses by adding the currentSport.ticketPrice to the accumulator. After the completion of the iteration, the variable totalTicketPrice holds the final result,43.</p><p>find(), filter(), map(), and reduce() are essential as they allow developers to work with array data without altering the original array.</p><p>These built-in methods not only perform specific operations on array elements but also serve as clear signals to other engineers. These methods give insight into the processes applied and the intended outcomes when working with a given array.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b483b6562e5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>