<?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 Joshua Mclean on Medium]]></title>
        <description><![CDATA[Stories by Joshua Mclean on Medium]]></description>
        <link>https://medium.com/@joshmcleana?source=rss-55c390e13e10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2hylz2Aj4hQhWkfAbxX_9A.jpeg</url>
            <title>Stories by Joshua Mclean on Medium</title>
            <link>https://medium.com/@joshmcleana?source=rss-55c390e13e10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:52:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joshmcleana/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[The Equal Opportunity Web]]></title>
            <link>https://medium.com/swlh/the-equal-opportunity-web-839b66e0499d?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/839b66e0499d</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[information-technology]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Thu, 05 Nov 2020 08:43:36 GMT</pubDate>
            <atom:updated>2020-11-06T08:17:14.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMSNe37lJFgsfUxOsaULEQ.png" /><figcaption>Bitmoji-Josh Loves the internet!</figcaption></figure><h4>Web Accessibility</h4><h4>An Introduction To Accessibility Standards</h4><p>Overview:</p><p><a href="#ddc0"><strong>1. Web Accessibility Around The World</strong></a></p><p><a href="#010a"><strong>2. ATAG, WCAG, and UAAG — Accessibility Guidelines</strong></a></p><p><a href="#6549"><strong>3. Modern Web Accessibility</strong></a></p><p><a href="#174d"><strong>4. Narratives On Accessibility</strong></a></p><p>Most people interact with computers and the internet to display content in an easily digestible format. This is accomplished with a wide variety of web technologies and programs that enable our access to the web. We don’t have to deal with giving the computer instructions via code or working in databases when surfing or buying products online. Web developers have done the hard work to provide us with interfaces and applications that are user-friendly abstractions of complex interactions.</p><p>Those sorts of abstractions provide <strong>accessibility</strong> to users. Most users don’t need to know deep computer science or be proficient in multiple programming languages to use computers to work or browse the web. As we know, and should make a habit of knowing, not all users are the same, so designing accessible programs and web applications is critical to serving the entire spectrum of users who could benefit from the internet. There is a lot to dive into on the topic of accessibility, so think of this story as a overview of key accessibility information and where to find it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Web Accessibility Around The World</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QI8xHzo3gsfPEZRDeORNjQ.png" /><figcaption>Bitmoji-Josh presents the world of the internet.</figcaption></figure><h4>W3C</h4><p>The World Wide Web Consortium (W3C) is an organization that develops international standards for the web and its technologies. They are all about making the web awesome and widely available. For accessibility, W3C partnered with organizations worldwide across industries, governments, and disability research and advocacy groups to develop the Web Accessibility Initiative (WAI).</p><h4>WAI</h4><p>The WAI was established in 1997 to improve the accessibility of the web for users. Comprised of volunteers and staff worldwide, The WAI worked to develop and approve accessibility standards, as well as provide open access to resources and education on web accessibility. The WAI website lists several examples of the components that work together to describe web accessibility:</p><ul><li><strong>Content</strong> — the information on a web page or web application, including natural information such as text, images, and sounds</li><li><strong>Code or markup</strong> that defines the structure, presentation, etc.</li><li><strong>Web browsers, media players</strong>, and other “user agents”</li><li>In some cases, <strong>assistive technology </strong>— screen readers, alternative keyboards, switches, scanning software, etc.</li><li><strong>Users</strong>’ knowledge, experiences, and in some cases, adaptive strategies using the web</li><li><strong>Developers</strong> — designers, coders, authors, etc., including developers with disabilities and users who contribute content</li><li><strong>Authoring Tools</strong> — software or applications that create websites or web content.</li><li><strong>Evaluation Tools</strong> — web accessibility evaluation tools, HTML validators, CSS validators, etc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*Mj6JQVlLqISq0o-pf7rbgg.png" /><figcaption>Graphic showing the relationship of web accessibility components.</figcaption></figure><p>Developers use user authoring and evaluation software to create content for the web. Users use their experience with the web and various assistive technologies to consume or use that content.</p><p>The W3C/WAI groups the components into three categories of guidelines to develop web accessibility standards:</p><ul><li>Authoring Tool Accessibility (ATAG)</li><li>Web Content Accessibility (WCAG)</li><li>User Agent Accessibility (UAAG)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>ATAG, WCAG, and UAAG — Accessibility Guidelines</h3><p>Each of these guidelines could have entire articles written about them individually. Here is a summary of what they cover.</p><h4>Authoring Tool Accessibility (ATAG)</h4><p>The Authoring Tool Accessibility Guidelines are primarily for developers who develop and maintain software that creates or generates websites or web content.<br>The guidelines cover two main parts:<strong> making your authoring tool’s interface accessible</strong> and <strong>supporting accessible content production. </strong>Both are important, but it&#39;s worth noting that authoring tools that support and encourage accessible web content, then it is easier for authors(users/developers) to implement those designs. Essentially, if it’s easy for users of the tools to make what they produce accessible, they will do so more often.</p><h4>Web Content Accessibility (WCAG)</h4><p>The Web Content Accessibility Guidelines are for web developers, web authoring tool developers, and users who would like a standard for building accessible web content. Adhering to these guidelines require that your web content is:</p><ul><li><strong>Perceivable — </strong>Can a user see and hear your content? Can a user use alternatives for non-text content? Can your content be delivered in different ways, compatible with different assistive technologies?</li><li><strong>Operable — </strong>Can a user interact with your content with the keyboard? Do you give users enough time to interact with your content? Can a user use input devices other than a keyboard? How easy is your site to navigate? Do you have any content that may cause seizures?</li><li><strong>Understandable — </strong>Is your content readable and understandable? Does the content appear predictably? How can you help a user avoid input mistakes?</li><li><strong>Robust — </strong>How future proof is your content in terms of accessibility?</li></ul><h4>User Agent Accessibility (UAAG)</h4><p>The User-Agent Accessibility Guidelines refer to the accessibility of user-facing software and applications that render web content (browsers, browsers extensions, etc.) This is especially targeting the accessibility of the user agent interface. The guidelines cover many of the same things from the previous two categories but especially deals with accessibility options that the user agent provides that are separate from the web content itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Modern Web Accessibility</h3><h4>WAI-ARIA</h4><p>ARIA stands for Accessible Rich Internet Application. WAI-ARIA is a standard that outlines methods and provides tools so developers can make web applications that use recent web technologies more accessible.</p><p>This applies to web applications that use AJAX requests, JavaScript, HTML, and similar technologies to update information on a page based on user interactions. Examples include pages that render content with sliders, dropdowns, modals, and navigable menus. JavaScript UI Libraries like React, Vue, and Angular often fall into the category of Rich Internet Applications.</p><p>Some common situations with Rich Internet Applications that can impact accessibility are regions of a web page that change in real-time or in response to a user’s input. Screen readers require solutions to read this content, like content from modals, that may change or disappear.</p><p>ARIA is a part of HTML5, which introduced new HTML standards for writing semantic accessible HTML documents. Tags like &lt;section&gt;, &lt;article&gt;, &lt;nav&gt; etc. were introduced to define regions of webpages with a little extra meaning, which cut down on screen readers needing to parse through extensive trees of&lt;div&gt; tags.</p><p>Overall, ARIA pro ides roles and properties to better describe web elements to assistive devices and technologies. These roles may describe a menu&#39;s behavior or specify a region of content and the actions a user can take in that region. Skip links and hidden navigation, so users don’t have to press tab to find their way around, and adding support for more types of assistive devices and technologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Narratives On Accessibility</h3><h4>User Stories</h4><p>To understand how important it is to consider accessibility in design, it’s useful to consider some narratives that are perhaps outside of our own. I included an example narrative from the W3C/WAI website and links to more at the bottom.</p><blockquote>Kaseem is a teenager who is deaf and recently became legally blind too, which means she can see only small portions of a screen and read text when it is significantly enlarged.</blockquote><blockquote>Kaseem uses:</blockquote><blockquote>screen magnification software to enlarge the text on websites to a suitable font size;</blockquote><blockquote>screen reader software that displays text on a refreshable Braille device;</blockquote><blockquote>large computer screen with high resolution and high luminosity (brightness).</blockquote><blockquote>Kaseem’s portable electronic Braille notetaker includes a calendar, e-mail, web browsing, and note-taking functionality. Her mobile device includes GPS which helps her orient herself and navigate around the city. Kaseem uses the public transportation online site to plan her trips and view bus schedules, but encounters problems when she enlarges the text and it does not reflow or wrap properly, making the maps very difficult to use. She has a better experience viewing the train schedules that are properly marked up and allow text reflow. Kaseem found the web team contact information listed at the public transportation website and sent a message to the team informing them of the problems she encountered using their site. She also sent them the link to the train website and described how that site works better for her. She recently received an email message thanking her for her information and informing her that the public transportation web team plans to implement accessibility improvements in the launch of their new website.</blockquote><h4>SOURCES</h4><p><a href="https://www.w3.org/WAI/">Web Accessibility Initiative — WAI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=839b66e0499d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-equal-opportunity-web-839b66e0499d">The Equal Opportunity Web</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Four-Step Guide for Solving Algorithms]]></title>
            <link>https://medium.com/dancing-syntax/four-step-guide-for-solving-algorithms-4ee02cb6b896?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ee02cb6b896</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[dancingsyntax]]></category>
            <category><![CDATA[journal]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 06:09:17 GMT</pubDate>
            <atom:updated>2020-11-04T06:36:42.121Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CkY275eTtTWtPIKBnFwgw.png" /><figcaption>Welcome to Part 2 of my Algorithm Journal!</figcaption></figure><h4>Algorithm Journal #2</h4><h4>Problem Solving Tips for both Technical and Non-Technical Problems</h4><p>Overview:</p><p><a href="#4d95"><strong>1. Understand the problem</strong></a></p><p><a href="#737d"><strong>2. Explore Specific Examples</strong></a></p><p><a href="#cc87"><strong>3. Break it Down, Then Solve</strong></a></p><p><a href="#33c0"><strong>4. Analyze &amp; Refactor</strong></a></p><p><a href="#48cf"><strong>5. Sources</strong></a></p><h3>Introduction</h3><p>In the previous story, I walked step by step through an algorithm. Since that was an introduction, I didn’t go into too many specifics and directly showed an algorithm example. Now we’ll go into greater detail, so let’s hang ten and jump right in! We will go over a non-technical example first, and then look at an algorithm that stumped me because I didn’t understand it at first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wP5WzCVF1i0Wul-GV7cfSw.png" /><figcaption>Bitmoji-Josh: Soon, I’ll look at Algorithms with the confidence of a person surfing on the tail of a dinosaur.</figcaption></figure><h3>Step 1: Understand the Problem</h3><p>Say we have this problem to solve:</p><blockquote>Make a <strong>sandwhich</strong> with the following ingredients: <strong>Bread, Mustard, Mayonaise</strong>(or literally anything else), <strong>Cheese</strong>, <strong>Ham, Tomato, and Lettuce.</strong></blockquote><p>Our very first step before doing anything is to make sure we can understand specifically what problem we are solving. So let’s ask some questions and make observations about the problem to <strong>guide our understanding.</strong></p><h4><strong>Say the problem out loud in your own words, write it down.</strong></h4><blockquote>Make a yummy snack that is comprised of bread and other snadwhich making ingredients.</blockquote><p>Alrighty, best not to overthink it past that. If interviewing, we may even get a reaction from an interviewer that serves up hints based on how we restate the problem. This shows that we can pick out the essential language and think about it in terms that make sense to us.</p><h4>What are the input(s) that go into the problem &amp; what are the Expected Output(s)?</h4><p>What data or items are we starting with and where are we trying to go? This one is pretty simple for this problem. For inputs, we have a list of sandwich ingredients: <strong>Bread, Mustard, Mayonnaise</strong>(yuck), <strong>Cheese</strong>, <strong>Ham, Tomato, and Lettuce.</strong></p><p>For output, we have a <strong>single constructed sandwich</strong>.</p><h4>Do we have enough information about the problem?</h4><p>Is what we know about the inputs, constraints, and details about the problem enough to make a deterministic solution? This means that we can arrive at the output as long as the proper inputs are present and the conditions required are met.</p><p>If we are interviewing, this is where we ask questions like, “Can I assume X?”, “What are the upper and lower limits (or constraints) of Y?”, “Do I have Z tool available to me?”</p><p>We can imagine asking about what exactly constitutes a sandwich, and if the order of ingredients matters, so let&#39;s add two assumptions in our restatement: A <strong>sandwich must consist of two slices of bread</strong> and the <strong>ingredients have a recommended order of layering</strong>. Our new statement reads:</p><blockquote>Make a yummy snack that is comprised of two slices of bread and has several ingredients layered in a recommended order(list).</blockquote><p>(No, there is no such thing as an open-faced<strong> sandwich</strong>. There’s only one piece of bread, sometimes require utensils, and don’t actually sandwich anything. Fight me if you disagree 😛 👨🏾‍🍳)</p><h4>Identify the important pieces of data</h4><p>Personally, I like to label the important pieces with some combination of <strong>bolding, </strong>CAPITAL LETTERS, side notes, and diagrams for visualization. For example, I recently solved a problem involving data structures to represent a grid. It would have been very tough to solve the problem without drawing a diagram first. Finally, does the above information help us determine what is important?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3NBI58aAniGA0Ygoi4zfg.png" /><figcaption>Bitmoji-Josh uses a magnifying glass to make sure he understands the problem to solve. Sometimes it takes two!</figcaption></figure><h3>Step 2: Create Test Examples</h3><p>Create examples to model the specific cases your solution needs to handle. Doing so helps us both understand the problem better and catch any errors we may have overlooked when we initially wrote out a problem. Here’s an example:</p><pre>Implement a function called areThereDuplicates which accepts a variable number of arguments, and checks whether there are any duplicates among the arguments passed in.</pre><pre>areThereDuplicates(1, 2, 3, 4, 4); //=&gt; <strong>true</strong><br>areThereDuplicates(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;d&quot;); //=&gt; <strong>true</strong><br>areThereDuplicates(1, 2, 3); //=&gt; <strong>false<br></strong>areThereDuplicates(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;); //=&gt; <strong>false</strong><br>areThereDuplicates(); //=&gt; <strong>null</strong></pre><p>Here, we write our test cases by building magic functions that describe the specific expected outputs for specific inputs. Doing so gives us a roadmap of cases for our solution to address, which deepens our understanding of the problem. Other ways we can write examples include user stories and unit tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axCV2mkBmzA2x9dDBwRkxg.png" /><figcaption>Bitmoji-Josh sitting at a desk with the words “Knowledge is Power” in the background.</figcaption></figure><h3><strong>Step 3: Break it down first, then solve</strong></h3><p>At this point, we can begin our first steps towards solving the problem. Let’s continue with the problem from before.</p><h4>Write an outline of steps needed to take</h4><pre>function areThereDuplicates(){</pre><pre>// handle <strong>variable number of arguments<br></strong>// handle no arguments passed<br>// handle only one argument passed</pre><pre>// Make a <strong>counter object</strong> to track frequency of argument occurence</pre><pre>// <strong>iterate over all arguments</strong>, for each argument:<br>// if the argument doesn&#39;t exist as a key in the counter, create <br>// that argument&#39;s key at set it&#39;s value to 0 <strong>OR</strong> increment it by 1</pre><pre>// <strong>iterate over the counter object,</strong> for each key:<br>// if the key&#39;s value is greater than 1<br>// return true</pre><pre>//otherwise:<br>//return false</pre><pre>}</pre><p>Above, we’ve now extended our problem-solving roadmap to include the specific steps that we will take to implement our solution. This problem is about counting beans and the beans are the arguments passed in. We can use a frequency counter in order to count if there are duplicate arguments. <br>When I first encountered this problem, I realized it was the first time I had to consider that I wouldn’t always know what or how many arguments are passed to the function. How do I work with this then? A quick Google search led me to this on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments">MDN</a>:</p><blockquote><strong>arguments</strong> is an Array-like object accessible inside <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions">functions</a> that contains the values of the arguments passed to that function.</blockquote><p>Perfect, with this information and our outline we can now write actual code!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZkj74S9slOvYSHwEW5Dog.png" /><figcaption>Bitmoji-Josh is ready to write some code.</figcaption></figure><h4>Make the function by replacing the outline with actual code</h4><p>Pro-tip: if we get to a part we don’t know how to implement, we can reuse our “magic functions” idea here too!</p><pre>Say we didn&#39;t know how to count each argument, me may choose to write: </pre><pre><strong>function areThereDuplicates(){</strong></pre><pre>//edge cases<br>if (arguments.length === 0) {<br>return null;<br>}<br>if (arguments.length === 1) {<br>return false;<br>}</pre><pre>// Make a counter object to track frequency of argument occurence<br>let counter = {}</pre><pre>// iterate over all arguments, for each argument:<br>// if the argument doesn&#39;t exist as a key in the counter, create <br>// that argument&#39;s key at set it&#39;s value to 0 OR increment it by 1</pre><pre><strong>// logic that sets the matching value of an argument&#39;s counter key // to 0 or adds 1 to the count<br>// counter = {&quot;a&quot;: 1, &quot;b&quot;: 1, &quot;c&quot;: 1}</strong></pre><pre>// iterate over the counter object, for each key:<br>// if the key&#39;s value is greater than 1<br>// return true</pre><pre>let keys = Object.keys(counter)<br>for (let i = 0; i &lt; keys.length; i++){<br>  if (counter[keys[i]] &gt; 1) {<br>     return true;<br>     }<br>  }</pre><pre>//otherwise:<br>//return false</pre><pre><strong>return false</strong><br><strong>}</strong></pre><p>The idea being that we can move on assuming that we have implemented that part of the functions, which can save us a lot of time and demonstrate that we have a clear idea of where we are going, if not how we will get there.</p><h4>Solve!</h4><pre><strong>function areThereDuplicates(){</strong></pre><pre>//edge cases<br><strong>if (arguments.length === 0) {<br>return null;<br>}<br>if (arguments.length === 1) {<br>return false;<br>}</strong></pre><pre>// Make a counter object to track frequency of argument occurence<br><strong>let counter = {}</strong></pre><pre>// iterate over all arguments, for each argument:<br>// if the argument doesn&#39;t exist as a key in the counter, create <br>// that argument&#39;s key at set it&#39;s value to 0 <strong>OR</strong> increment it by 1</pre><pre><strong>for (let i = 0; i &lt; arguments.length; i++){<br>  if (counter[arguments[i]] === undefined){<br>       counter[arguments[i]] = 0<br>    } else {<br>       counter[arguments[i]]] + 1<br>   }<br> }</strong></pre><pre>// iterate over the counter object, for each key:<br>// if the key&#39;s value is greater than 1<br>// return true</pre><pre><strong>let keys = Object.keys(counter)<br>for (let i = 0; i &lt; keys.length; i++){<br>  if (counter[keys[i]] &gt; 1) {<br>     return true;<br>     }<br>  }</strong></pre><pre>//otherwise:<br>//return false</pre><pre><strong>return false</strong><br><strong>}</strong></pre><p>Above represents my <strong><em>first solution</em></strong><em>. </em>This doesn’t mean we are done yet, but hooray, problem solved!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QyD3esAX98YpkjDMkgHDA.png" /><figcaption>Bitmoji-Josh celebrates!</figcaption></figure><h3>Step 4: Analyze &amp; Refactor!</h3><p>In the previous step, we have arrived at a solution. Now we can look back and ask which ways we can make it better. Normally, we would first analyze the time and space complexity of the algorithm, but I won’t do that here because it right deserves it’s own story. However, there are other questions we can ask like:</p><p>Can I check the results?</p><p>Can I derive the result differently?</p><p>Now that I have solved the problem, what other things could I have done?</p><p>Can I understand it at a glance?</p><p>How legible is it?</p><p>Can I use the result or method for other problems?</p><p>What similarities does my solution have to other problems?</p><p>Can I improve the performance of my solution?</p><ul><li>Time and Space Complexity, finding bottlenecks</li></ul><p>Can I think of other ways to refactor?</p><ul><li>Style guides, spacing consistent, etc.</li></ul><p>How have others solved this solution?</p><p>Can find ideas or different approaches in other people’s work/other languages?</p><p>Here are two refactors to this problem:</p><pre>Refactor 1: Clean up loops and use more modern JavaScript Syntax</pre><pre>function areThereDuplicates() {</pre><pre>  //edge cases<br>  if (arguments.length === 0) {<br>  return null;<br>  }</pre><pre>  if (arguments.length === 1) {<br>  return false;<br>  }</pre><pre>  let frequencyCounter = {};</pre><pre>  for (let index in arguments) {<br>   frequencyCounter[arguments[index]] =<br>    (frequencyCounter[arguments[index]] || 0) + 1;<br>    }</pre><pre>  for (let key in frequencyCounter) {<br>   if (frequencyCounter[key] &gt; 1) {<br>    return true;<br>    }<br>  }</pre><pre>return false;</pre><pre>}</pre><p>Above we use for...in loops to clean up our looping logic and we use a Ternary statement and the logical OR || operator for setting the initial value or adding 1 to it if it exists.</p><pre>Refactor 2: One Liner using JavaScript Set</pre><pre>function areThereDuplicates() {<br>    return new Set(arguments).size !== arguments.length;<br>}</pre><p>On <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">MDN</a>, it reads:</p><blockquote>Set objects are collections of values. You can iterate through the elements of a set in insertion order. A value in the Set <strong>may only occur once</strong>; it is unique in the Set&#39;s collection.</blockquote><p>So the logic going on here is to create a Setwith the function’s passed in arguments and compare the size of new Set to the length of the original arguments object. Since the Setchecks for uniqueness, if they are unequal we know that there are duplicates in the original arguments object.</p><h3>Conclusion</h3><p>Following the steps to make sure we understand what problem we are trying to solve, have examples that we can test against, breaking it down before solving, and then analyzing before refactoring is a tried a true method of approach solve algorithms, general coding problems, and with not so much mental leg-work, life’s problems too!</p><p>I hope this is useful to you. Studying it and writing about it sure has been for me. Enjoy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tz_7VDx8fIi5Yx5o7wX7g.png" /></figure><h3>Sources:</h3><ol><li><a href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/">Colt Steele’s JavaScript Data Structures and Algorithms Masterclass on Udemy</a>.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments">MDN — JavaScript </a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments">arguments object.</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">MDN — JavaScript </a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">Set</a></li></ol><blockquote><em>What did you think about this post? See something inaccurate? We’d love to hear from you! Leave a comment about your tips and approach to algorithm solving, or just about anything else! Looking to find out more about Joshua? </em><a href="https://medium.com/dancing-syntax/hello-world-im-joshua-2cbe32b97003"><em>Read this story</em></a><em> and follow him on social media!</em></blockquote><blockquote><em>Interested in contributing to this publication? Start a conversation with me at </em><a href="/service/mailto:dance.syntax@gmail.com"><em>dance.syntax@gmail.com</em></a><em>, I promise I don’t bite. 😁</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ee02cb6b896" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dancing-syntax/four-step-guide-for-solving-algorithms-4ee02cb6b896">Four-Step Guide for Solving Algorithms</a> was originally published in <a href="https://medium.com/dancing-syntax">Dancing Syntax</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With Algorithms]]></title>
            <link>https://medium.com/dancing-syntax/getting-started-with-algorithms-64ee7e6ecee0?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/64ee7e6ecee0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Tue, 27 Oct 2020 00:40:32 GMT</pubDate>
            <atom:updated>2020-11-04T06:18:05.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ony51Rd2hVF6lV9PUZNT6w.png" /><figcaption>Help, Bitmoji-Josh is confused by algorithms and can’t escape the whiteboard!</figcaption></figure><h4>Algorithm Journal</h4><h4>Algorithm solving process and resources to support your education.</h4><p>Overview:</p><p><a href="#99ee"><strong>1. What are Algorithms? Why are they useful?</strong></a></p><p><strong>2. </strong><a href="#3745"><strong>Example and Process</strong></a><strong>.</strong></p><p><strong>3. </strong><a href="#eb95"><strong>Optimizing our solution</strong></a><strong>.</strong></p><p><strong>3a. </strong><a href="#2d36"><strong>Refactored Solution</strong></a><strong>.</strong></p><p><strong>4. </strong><a href="#7ee4"><strong>Conclusion.</strong></a></p><p><strong>4a. </strong><a href="#fa18"><strong>Resources</strong></a><strong>.</strong></p><p><strong>4b. </strong><a href="#374d"><strong>Sources</strong></a><strong>.</strong></p><p>Here’s the deal folks, I’m TERRIFIED of algorithms. They aren’t scary for any particular reason, but facing them; and other problem-solving situations, brings up uncomfortable feelings and memories about learning that I like to avoid.</p><p>In order to conquer this terror and follow through on my commitment to becoming a software engineering superhero. It’s pretty clear that I’ll need to learn more about Algorithms. Many Computer Science topics, Algorithms, and Data Structures are part of what folks learn in College CS programs. Bootcamps like The Flatiron School and others work to prepare you in this regard, but honestly, you could study them in their own 3–4 month Bootcamp.</p><p>Let’s get started, shall we?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ncSvGj_vjm8DTin9aJzBpA.png" /><figcaption>Bitmoji-Josh is revving his engine, ready for algorithms. ARE YOU?!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>What are Algorithms? Why are they useful?</h3><p>Which of these scenarios can be considered an algorithm?</p><ul><li>Making a pizza</li><li>Finding the best route from point A to point B</li><li>Sorting a dataset</li><li>Finding a value in a dataset</li><li>Improving your family’s Holiday cookies</li><li>Counting “beans”</li></ul><p>Turns out all of these scenarios are <em>algorithmic in nature</em>! Simply put, <strong>algorithms are a well-defined, step-by-step procedure to complete any task. </strong>In computer programming, algorithms are the instructions we provide to computers to perform specific tasks that help us solve computational problems, or obtain results that are applicable to the real world.</p><blockquote>To be interesting, an algorithm must solve a general, well-specified problem. An algorithmic problem is specified by describing the complete set of instances it must work on and of its output after running on one of these instances. This distinction, between a problem and an instance of a problem, is fundamental.</blockquote><blockquote><em>— S.S. Skiena, The Algorithm Design Manual, 2nd ed.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBb2bKrc0vsIbyfibt_QZg.png" /><figcaption>Bitmoji-Josh holding a giant pencil.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Example and Process</h3><p>Let’s take a simple example: Counting “beans”</p><blockquote>Write a function that <strong>calculates the sum of all numbers from 1</strong> up to and including some number <strong>n</strong></blockquote><p>If we break this down we’re looking at writing a function that:</p><ul><li>Takes in a number <strong><em>n</em></strong></li><li>Starts at the <strong>number 1</strong></li><li>Adds each number together in sequence, up to and including <strong><em>n</em></strong></li><li>Returns that <strong>total</strong> when done</li></ul><p>Thinking about some examples helps to further clarify exactly what we are looking to accomplish.</p><pre>addUpto(3) //=&gt; <strong>6</strong><br>Because 1 + 2 + 3 = <strong>6</strong></pre><pre>addUpto(6) //=&gt; <strong>21</strong><br>Because 1 + 2 + 3 + 4 + 5 + 6 = <strong>21</strong></pre><p>Then we can write some placeholder code (a spec or pseudocode) to guide our actual code.</p><pre>function addUpto(n){<br>  /*<br>  Declare and assign variable to record total outside of loop<br>  <br>  Make a loop that:<br>  starts at 1<br>  runs as long as <em>i</em> is less than or equal to <em>n<br>  </em>adds i to total and assigns the new result to the total variable<br>  <br>  outside of loop: return total<br>  */<br>}</pre><p>After which we now can replace our steps with the code that does exactly what we just specced out.</p><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>  }<br>  return total;<br>}</pre><p>We can log to the console <strong><em>i</em></strong> and <strong><em>total</em></strong> to even further illuminate how our code is running.</p><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>    console.log(i, total)<br>  }<br>  return total;<br>}</pre><pre>addUpTo(6)</pre><p>Here is a diagram to show what our console logged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgV1Qol5spTtkCr2jhWN6g.png" /><figcaption>A truth table showing what <em>i and total are for each step of the iteration</em></figcaption></figure><ul><li>1st iteration: <strong><em>total</em></strong> is 0 and <strong><em>i</em></strong> is 1, summing that, we get total = 1</li><li>2nd iteration: <strong><em>total</em></strong> is 1 and <strong><em>i</em></strong> is 2, summing that, we get total = 3</li><li>3rd iteration: <strong><em>total</em></strong> is 3 and<strong><em> i</em></strong> is 3, summing that, we get total = 6</li><li>and so on until the last iteration: <strong><em>total</em></strong> is 15, and <strong><em>i</em></strong> is 6, which gives us 21</li></ul><p>So that wasn’t too bad… are we done? NOPE! This is a great first shot at solving this problem, but it can be improved. This solution; the first solution we develop when solving problems, is considered a <strong>Naive or Brute Force </strong>solution. That just means that we aren’t particularly focusing on optimizing our solution the first time around. However, this solution is a great stepping stone to a more optimal algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Optimizing our solution.</h3><p>Checking out this code again, we can analyze the complexity at-a-glance by counting the operations and accounting for the nature of looping:</p><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>  }<br>  return total;<br>}</pre><p>We have:</p><ul><li>one assignment for<strong><em> total</em></strong></li><li>one assignment for <strong><em>i</em></strong></li><li><strong><em>n</em></strong> comparisons (<strong>i ≤ n</strong>)</li><li><strong>n</strong> additions</li><li><strong>n</strong> assignments to total</li><li><strong>n</strong> increments to iterator variable(i++)</li><li><strong>n</strong> assignments for iterator variable</li></ul><p>The nitty-gritty details and the language used to describe the computational complexity of an algorithm is known as <strong><em>Big O Notation</em></strong>. I’ll get into that in a future blog, but for now, let’s compare against a more optimal solution to the same problem.</p><h4>An in-depth look at our refactored solution.</h4><pre>function addUpToOptimized(n) {<br>return (n * (n + 1)) / 2;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SeFv7NnSeZC-qM2pl07vdQ.png" /><figcaption>Bitmoji Josh says “ZOMG!” and is puking rainbows at that mathy solution.</figcaption></figure><p>Woah, such a small amount of code! How does this work?</p><p>This problem is a famous one, mathematically speaking. At 10 years old, <a href="https://www.britannica.com/biography/Carl-Friedrich-Gauss">Carl Friedrich Gauss</a> was asked to add up all the numbers from 1 to 100 and did so in mere minutes.</p><p>I’m no math whiz myself, so I did some research about how this works, consider if n is 10 (or any even number):</p><pre> 1    2    3    4    5<br>10    9    8    7    6  <br>----------------------<br>11   11   11   11   11</pre><pre>If we line up the numbers like this we see that each column adds to 11 and that there are five 11’s, so the sum we want is 55</pre><pre>10 + 1 = 11 and 10 / 2 = 5</pre><pre>So essentially, we have (10 + 1) * (10 / 2) or 11 * 5 = 55</pre><pre>This means that when we want to sum numbers from 1 to n, where n is any number we can use the formula <strong>(n + 1) * (n / 2)</strong></pre><pre>We can rewrite that expression as <strong>(n * (n + 1)) / 2</strong></pre><p>Let’s count the operations of this function, <strong>given that simple mathematic operations take a constant amount of time to compute!</strong></p><pre>function addUpToo(n) {<br>return (n * (n + 1)) / 2;<br>}</pre><p>We have:</p><ul><li>one multiplication</li><li>one addition</li><li>one division</li></ul><p>Much less complex!</p><p>Remember, there is more detailed language; called <strong><em>Big O Notation, </em></strong>that is used to analyze the <strong><em>time complexity</em></strong>(how long your algorithm takes to run) and <strong><em>space complexity</em></strong>(how much memory your algorithm requires to run). You can look for that in our upcoming stories!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Conclusion.</h3><p>I recognize now that I have a brilliant mind “square peg” that I’ve been trying to stuff into traditional education’s “round hole” for years. That has left me with many negative presumptions and fears about my ability to learn and focus.</p><p>Since problem solving and algorithms are a cornerstone to software engineering, having a good process to approach each problem makes everything waaaay less intimidating. Onwards and upwards!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXgihgTWi3KR74-oG-kbXg.png" /><figcaption>An alternate reality where rapping about algorithms is wicked cool.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h4>There are great resources for you to support your learning. Some of them are even FREE.</h4><ul><li><a href="https://www.khanacademy.org/computing/computer-science/algorithms">Courses offered by Khan Academy</a> (FREE)</li><li>Courses offered on Cousera, Udemy, and similar professional development skill sites. — <a href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass">I took this one by Colt Steele on Udemy.</a> depending on the site, you can find classes that are paid, reduced cost, or free.</li><li>People you may know who are Software Engineers, and/or have CS Degrees (Often FREE if you’re friends 😁)</li><li>Youtube videos (FREE) — I particularly like the videos by <a href="https://www.youtube.com/channel/UCOf7UPMHBjAavgD0Qw5q5ww">HackerRank</a>, <a href="https://www.youtube.com/c/BenAwad97">Ben Awad</a>, and this video showing <a href="https://www.youtube.com/watch?v=kPRA0W1kECg">visualizations of sorting algorithms by Timo Bingmann</a>.</li><li>Books like <em>Cracking The Coding Interview</em> by Gayle Laakmann McDowell — McDowell also does many of the HackerRank Youtube Videos</li><li>The Algorithm Design Manual by <a href="https://scholar.google.com/citations?user=fnE2dSoAAAAJ&amp;hl=en">Steven S. Skiena</a> ← This is amazing and has become my bible.</li></ul><h4>Sources.</h4><ul><li>The Algorithm Design Manual by <a href="https://scholar.google.com/citations?user=fnE2dSoAAAAJ&amp;hl=en">Steven S. Skiena</a></li><li><a href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass">Javascript Data Structures and Algorithms Master Class by Colt Steele on Udemy</a></li><li><a href="https://www.britannica.com/biography/Carl-Friedrich-Gauss">Carl Fredrick Gauss</a> — Britannica.com</li><li><a href="http://mathforum.org/library/drmath/view/57990.html">Math Forum “Ask Dr. Math” Sum numbers 1–500</a></li></ul><blockquote>What did you think about this post? See something inaccurate? We’d love to hear from you! Leave a comment about your favorite tipss that helped you crush algorithms, or just about anything else! Looking to find out more about Joshua? <a href="https://medium.com/dancing-syntax/hello-world-im-joshua-2cbe32b97003">Read this story</a> and follow him on social media!</blockquote><blockquote>Interested in contributing to this publication? Start a conversation with me at <a href="/service/mailto:dance.syntax@gmail.com">dance.syntax@gmail.com</a>, I promise I don’t bite. 😁</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64ee7e6ecee0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dancing-syntax/getting-started-with-algorithms-64ee7e6ecee0">Getting Started With Algorithms</a> was originally published in <a href="https://medium.com/dancing-syntax">Dancing Syntax</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welcome to Dancing Syntax: Learn About Us!]]></title>
            <link>https://medium.com/dancing-syntax/welcome-to-dancing-syntax-learn-about-us-5b5430213c21?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b5430213c21</guid>
            <category><![CDATA[blacklivesmatter]]></category>
            <category><![CDATA[writer]]></category>
            <category><![CDATA[adhd]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[inspiration]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 12:33:17 GMT</pubDate>
            <atom:updated>2020-10-27T05:40:43.775Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNwIokeO2LadJywYuFkRmQ.png" /><figcaption>Bitmoji-Josh welcomes you to Dancing Syntax!</figcaption></figure><h4>New Publication!</h4><h3>Welcome, Learn About Us!</h3><h4>Writing about Code, Dance, Life, and More.</h4><p>Overview:</p><ol><li><a href="#5236"><strong>Purpose</strong></a></li><li><a href="#99ee"><strong>Preclude to War</strong></a></li><li><a href="#41a4"><strong>Redefining Self</strong></a></li></ol><h3>Purpose</h3><p>Hi there! I’m Joshua Mclean; <a href="https://medium.com/dancing-syntax/hello-world-im-joshua-2cbe32b97003">you can read more about me here</a>. Dancing Syntax is my new publication here on medium. It’s where you can find both my writings on code and dance, as well as contributions from other enterprising writers.</p><p>I’m a career transitioner with a storied past. Y’know that saying, <em>“When life gives you lemons, make lemonade</em>?<em>”</em> Well, my version of that is a twisted Rube Goldberg Machine, but hey, it’s working! Making changes in my life has been scary, especially in response to COVID-19 and healing trauma.</p><p>Deciding to write on Medium is not just to demonstrate my learning processes or show what I have learned, but to better record my progress and face those fears constructively with writing. Interested? Well, buckle up because it’s <em>bellum contra te ipsum</em> time baby, I’m going to war with myself!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLg06HirfVavIFb_-T91vg.png" /><figcaption>Bitmoji-Josh is dressed and prepared for battle with his green “mind” tank.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Preclude to War</h3><p>Today, I am setting my intention to contend with myself as a <em>learner. </em>I was born in 1994, just two months before the U.S prison population would jump past 1 million people, disproportionately affecting Black Americans. My mother, a single parent working two jobs, was determined that I’d get an excellent education, so she decided to homeschool.</p><p>That fed my curiosity well, and I developed a love for learning early on. There was just one issue, around four years old; I was diagnosed with ADHD. My mother was terrified of me slipping through the cracks in “the system,” so she treated the diagnosis as a fake label. A man even told her that such things would become my crutch if she let them. Thus, my ADHD went untreated for much of my life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Redefining Self</h3><p>The day before I wrote this, I went to my doctor’s office at 26 years old and completed the <a href="https://add.org/wp-content/uploads/2015/03/adhd-questionnaire-ASRS111.pdf">Adult ADHD Self-Report Scale (ASRS-v1.1) Symptom Checklist</a>. It’s a questionnaire broken up into two parts with 18 total questions. It asks readers to rate themselves based on a scale of Never-Rarely-Sometimes-Often-Very Often.</p><p>I answered “Very Often” to all but two of the questions, I was shocked at how closely the descriptions matched my experience. Growing up with ADHD felt like getting trapped in a room with the water level slowly rising. Early on, my behaviors were likened to those of any child, but that ebbed away as I got older. I felt that I was fighting a losing battle with my confidence and self-esteem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3zjGsaOssisxJZulyCVmA.png" /><figcaption>Bitmoji-Josh feels like he is drowning.</figcaption></figure><p>Over the years, I’ve come to regard myself as anything but the quick-witted, badass, multi-talented, hyper-aware, and budding polymath that I know myself to be, but rather, a fraud. Just functional enough for others to have zero clues what’s going on (including myself), yet inattentive and struggling to perform tasks or conducting activities other people seemed to handle with ease.</p><p>Learning to care for me has been a journey. After graduating from the Software Engineering Bootcamp at Flatiron School, I felt that tackling ADHD and building better atomic habits are among the last few puzzle pieces I’ve needed to realize my potential and redefine myself altogether. It is my sincere hope that this publication also helps someone else find their puzzle pieces. I’m certainly not there yet, but I can see it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H91FHmdn-CTui2W_GiD8wQ.png" /><figcaption>Bitmoji-Josh Says, “We Got This!”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><blockquote>What did you think about this post? We’d love to hear from you! Leave a comment about your own gripes with life’s lemons, ADHD, or just about anything else! Looking to find out more about Joshua? <a href="https://medium.com/dancing-syntax/hello-world-im-joshua-2cbe32b97003">Read this story</a> and follow him on social media!</blockquote><blockquote>Interested in contributing to this publication? Start a conversation with me at <a href="/service/mailto:dance.syntax@gmail.com">dance.syntax@gmail.com</a>, I promise I don’t bite. <em>😁</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b5430213c21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dancing-syntax/welcome-to-dancing-syntax-learn-about-us-5b5430213c21">Welcome to Dancing Syntax: Learn About Us!</a> was originally published in <a href="https://medium.com/dancing-syntax">Dancing Syntax</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Calendar Heatmap with SVG and React.js]]></title>
            <link>https://javascript.plainenglish.io/building-a-calendar-heatmap-with-svg-and-react-js-6751b19a2d95?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/6751b19a2d95</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[calendar]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 01:37:56 GMT</pubDate>
            <atom:updated>2020-08-03T02:00:59.101Z</atom:updated>
            <content:encoded><![CDATA[<h4>Dancing Syntax</h4><h4>Supporting emotional self-awareness through Data Visualization</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kidklsO9gEqsnXm1l9hBQ.jpeg" /><figcaption>A Calendar — Photo by <a href="https://unsplash.com/@nhillier">Nick Hiller</a> on Unsplash.</figcaption></figure><h3>Introduction</h3><p>In 2016, I had put my academic plans on hold after my first year and a half of college in order to take care of my younger sibling when our mother was unable to. Some really amazing friends of mine stepped in to help me out and eventually ended up adopting her (and effectively me too!).</p><p>After we stabilized, I felt the urge to return learning something other than dance, and I eventually ended up attending Flatiron School. It had been about five years since I had been in a school-like environment, so managing stress and self-care was difficult. My struggles with my awareness around my self-care inspired me to make an app to help people manage their care better.</p><p>While pre-planning for my app, I reached out to my friends on Facebook and asked them what they would like and dislike out of a self-care app. I got over 60 responses in minutes. These responses helped to form some user stories for my app. One particular response was:</p><blockquote>It would be cool to have some sort of simple data visualization for how you feel every day so you could track it and learn when you need to take more time for yourself. Something as simple as a calendar you color code for feelings like yellow = anxious, etc.</blockquote><p>I thought this would be super cool, at the time of reading this suggestion, I didn’t quite know how I would do it, and I dreaded working with dates in programming, but I set out to accomplish it, so let’s do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>The Fun Part</h3><h4>MVP</h4><p>In order to make this happen I know I needed to keep track of a few things:</p><ul><li>A user can pick from a list of feelings</li><li>Each feeling is mapped to a display color for that feeling</li><li>A dynamic, functional calendar to display the colors of a feeling on the given day when the feeling was reported</li></ul><p>I decided that the minimum viable product, or “skateboard”, version of this would group my feelings into categories of “Needs Satisfied” and “Needs Unsatisfied” → then categories of parent words → then highly specific feeling words. I did it this way to support a user deepening their <em>emotional granularity</em> (read: specific understanding). For example, it’s more useful and specific to report that you felt empowered than confident. I did some research and came away with 217 feeling words to start with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*WqqFQrvcixnigB4VtpEOJg.png" /><figcaption>A portion of the 217 words I collected</figcaption></figure><p>I also decided that since I had so many words, I would assign colors to only the two topmost level categories, satisfied and unsatisfied. This will keep things simple and I plan to do more research into better words and mapping colors to feelings in a future refactor.</p><h4>Environment</h4><p>I’m using Ruby on Rails as a backend API with PostgreSQL as my database. I’m using React.js for my frontend client.</p><h4>Preparing the SVG</h4><p>For my project, I had the great pleasure to work with two designers, <a href="https://medium.com/u/4d2e5b0cbc9f">Anna Wu</a> and <a href="https://medium.com/u/86339748ded5">Kendra Jenel</a>. They created this graphic for me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVSCfzhr0fy5Jx3ZkdlDvA.png" /><figcaption>Ex. 1 Concept Calendar with colored squares to indicate feelings reported</figcaption></figure><p>After exporting it from Figma as SVG I edited the SVG to make the cells the same blank fill color and resized the first cell that highlights the current day in Ex. 1. Now it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inK8GcoFfwINE9ufYzbBeQ.png" /><figcaption>Blank Concept Calendar</figcaption></figure><p>From there I went to <a href="https://svg2jsx.com/">SVGtoJSX</a> in order to quickly turn this SVG into a React Component. You have to do this because not all SVG properties are valid JSX. For example: stroke-width = valid SVG, strokeWidth = valid JSX.</p><p>SVGtoJSX also allows you to toggle the presence of IDs and determine whether you want a functional or class component, as well as memorize and toggle single quotes or double quotes.</p><p>After all that, we have a React component to work with.</p><p>Currently, the displayed month is an SVG &lt;path&gt; which means that instead of text, it is drawn as a series of attributes telling the client where, how, and what to draw.</p><pre>&lt;path id=&quot;July&quot; d=&quot;M160.477 32.18C159.673 32.18 158.929 32.024 158.245 31.712C157.573 31.388 157.021 30.938 156.589 30.362L157.921 28.76C158.617 29.72 159.451 30.2 160.423 30.2C161.731 30.2 162.385 29.426 162.385 27.878V21.362H157.903V19.4H164.725V27.752C164.725 29.228 164.365 30.338 163.645 31.082C162.925 31.814 161.869 32.18 160.477 32.18ZM177.097 22.388V32H174.955V30.776C174.595 31.208 174.145 31.544 173.605 31.784C173.065 32.012 172.483 32.126 171.859 32.126C170.575 32.126 169.561 31.772 168.817 31.064C168.085 30.344 167.719 29.282 167.719 27.878V22.388H169.969V27.572C169.969 28.436 170.161 29.084 170.545 29.516C170.941 29.936 171.499 30.146 172.219 30.146C173.023 30.146 173.659 29.9 174.127 29.408C174.607 28.904 174.847 28.184 174.847 27.248V22.388H177.097ZM180.043 18.644H182.293V32H180.043V18.644ZM194.247 22.388L189.747 32.774C189.327 33.818 188.817 34.55 188.217 34.97C187.617 35.402 186.891 35.618 186.039 35.618C185.559 35.618 185.085 35.54 184.617 35.384C184.149 35.228 183.765 35.012 183.465 34.736L184.365 33.08C184.581 33.284 184.833 33.446 185.121 33.566C185.421 33.686 185.721 33.746 186.021 33.746C186.417 33.746 186.741 33.644 186.993 33.44C187.257 33.236 187.497 32.894 187.713 32.414L187.875 32.036L183.681 22.388H186.021L189.045 29.498L192.087 22.388H194.247Z&quot; fill=&quot;black&quot;/&gt;,</pre><p>In order to control what month is displayed, I made an array of these paths and a function to render that month &lt;path&gt; based on state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b96edf1377a11e5289d57134a629b00/href">https://medium.com/media/7b96edf1377a11e5289d57134a629b00/href</a></iframe><p>Refactor point: I’ll likely come back later and make this an object instead with the current month as the key to grab the month path.</p><p>Finally, I give all of my calendars’ SVG rectangles a date attribute set to &quot;blank&quot;, then I wrap the &lt;rect&gt;&lt;/rect&gt; nodes into row groups that represent weeks. Then give each row &lt;g&gt;&lt;/g&gt; an id, and wrap the entire calendar in a group for the month, giving it an id and onClick event listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Calendar Functionality</h3><h4>Setup</h4><p>This first step I took was to define some state to keep track of the current day, the current month, and the current year.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6466af89b62357f5d1d313fc7d8b0789/href">https://medium.com/media/6466af89b62357f5d1d313fc7d8b0789/href</a></iframe><p>In each function, I am defining a constant date and setting it equal to new Date() . According to MDN:</p><blockquote>JavaScript <strong>Date</strong> objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.</blockquote><p>As I am writing this it is Wednesday, July 29th so calling new Date() with no parameters gives me a date object for today’s date and the time is the time at which I initiated the Date() call. It displays in a human-readable format showing the GMT offset and my local time zone.</p><pre>new Date()<br>//=&gt; Wed Jul 29 2020 13:07:23 GMT-0700 (Pacific Daylight Time)</pre><p>I’m using the toLocaleString method in the interest of future-proofing this for different timezones, but I’ll likely refactor that down the road.</p><p>The next step is to get both the first day of the given month and the number of days in a given month.</p><p>I found <a href="https://medium.com/@nitinpatel_20236/challenge-of-building-a-calendar-with-pure-javascript-a86f1303267d">this blog post</a> on Medium by <a href="https://medium.com/u/fae9d84f67cb">Nitin Patel</a> which helped me figure out how to get this data (thanks!). Patel is generating their entire calendar using raw CSS and JavaScript, which is super cool so check that out for the extra challenge.</p><pre>// 1. Get days in given month, for given year.</pre><pre>       daysInMonth = (iMonth, iYear) =&gt; {<br>         return 32 - new Date(iYear, iMonth, 32).getDate();<br>       }</pre><pre>a. new Date(2020, 0, 32)<br>//=&gt; Sat Feb 01 2020 00:00:00 GMT-0800 (Pacific Standard Time)</pre><pre>b. new Date(2020, 0, 32).getDate()<br>//=&gt; 1</pre><pre>c. 32 - 1 <br>//=&gt; 31</pre><pre>//Jan 31st!</pre><pre>// 2. Get first day in given month, for given year.</pre><pre>       let firstDay = (new Date(year, month)).getDay();</pre><pre>a. new Date(2020, 0)<br>//=&gt; Wed Jan 01 2020 00:00:00 GMT-0800 (Pacific Standard Time)</pre><pre>b. (new Date(2020, 0)).getDay();<br>//=&gt; 3</pre><pre>//Wednesday!</pre><p>In Function 1, new Date(iYear, iMonth, 32).getDate() returns the numerical day of the 32nd day after the first day of the passed in month. JavaScript counts months start from 0 and the method getDay() returns the numerical day of the week, also starting the count from 0. We subtract that number from 32 and arrive on the final day for the passed in month.</p><blockquote><strong>Note:</strong> all the functions for setting state and populating the calendar are called within componentDidMount .</blockquote><pre>componentDidMount(){</pre><pre>this.setMonth()</pre><pre>this.setYear()</pre><pre>this.setCurrent()</pre><pre>this.populateCalendar(new Date().getFullYear(), new Date().getMonth())</pre><pre>}</pre><p>Now that I have this initial setup completed, I can move on to populating the calendar with dates.</p><h4>Loop-de-loop!</h4><p>Now for the fun part: Loops!</p><p>First, I add a ref to my constructor and attach that ref to the &lt;g&gt;&lt;/g&gt; that represents the month. React refs give us a way of referencing and accessing DOM nodes. You can access the attached node by calling .current on this.namedRef .</p><pre>constructor(props){<br>   super(props)<br>   this.monthRef = React.createRef()<br>}</pre><pre>...further down in file</pre><pre>&lt;g id=&quot;month&quot; ref={this.monthRef} onClick={this.handleClick}&gt;<br>...Week rows and Day Rectangles<br>&lt;/g&gt;</pre><p>Now, I’ll define my function that will take in a numerical year and month and define the variables I’ll need to start off my loopalooza. Here’s the code, and there’s a step by step following it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13c75710f39dde3b9b779a2d2b39613c/href">https://medium.com/media/13c75710f39dde3b9b779a2d2b39613c/href</a></iframe><h4>Step By Step</h4><ol><li>Iterate with a for loop through the month, cal.current.children will return an HTMLCollection which is our rows representing weeks. Each step of the row iteration will bring us to a new week.</li><li>Define a variable representing the current iteration week’s child day &lt;rect&gt;&lt;/rect&gt; .</li><li>Iterate again through the week, define a variable to represent the current iteration day &lt;rect&gt;&lt;/rect&gt; .</li><li>Now that we have iterated over the entire structure, we can start populating the date property on each &lt;rect&gt;&lt;/rect&gt;.</li><li>Check if we are on the first iteration and the second iteration’s numerical value is less than the value of firstDay. If true, continue the iteration. This will leave the date property on each rectangle “blank” until we hit the proper day of the week to start assign values.</li><li>Check if the numerical value of the date variable is greater than the returned numerical value of daysInMonth function. If true, we have completed assigning values and we can break from the loops. we will increment date outside our loops</li><li>Access the attributes of the currentCell at the current step of the nested loop and update the date value with the value from the date variable.</li><li>Check if the value of date ,month , and year are equivalent to today&#39;s date in state, if true, then adjust the style of the currentCell to highlight the current day of the month. Since the highlight is a black outline around the rectangle, I have to decrease the size of the rectangle and draw the outline, which will shift my rectangle up 2.5 pixels and left 3 pixels. The last two lines in this block will reposition the cell where it should be properly respective to the other cells.</li><li>For our next trick, the part that sends us on to greater things, we will define two variables to store a count of satisfied and unsatisfied category feelings and map over the User’s reported feelings.</li><li>Inside the map, define a variable that holds the feeling object that is the result of filtering the list of feelings for specific feeling ID that matches the UserFeeling’s “feeling_id”</li><li>Define a variable that reads the UserFeeling’s “created_at” attribute, and get the numerical day number for the date the record was created with .getUTCDate() .</li></ol><p>#11 is super important. In my development environment, PostgreSQL will store my “created_at” date as a representation of UTC (Coordinated Universal Time) in the format YYYY-MM-DD HH:MM:SS:MS, but on the JavaScript side, my record gets converted into an ISO8601 format string which looks like this: 2020–07–01T02:32:21.580Z</p><p>The “T” Separates the date from the time, the “Z” stands for “Zulu” and indicates the zone designation for the zero offset of UTC time. Check out this example.</p><pre>Rails/PostGresQL:</pre><pre>Records &quot;created_at&quot; stored as UTC:</pre><pre>2020-07-01 02:32:21.580076</pre><pre>Parse in JS (local time is the default):<br>new Date(“2020-07-01 02:32:21.580076”)</pre><pre>//=&gt; Wed Jul 01 2020 02:32:21 GMT-0700 (Pacific Daylight Time)<br></pre><pre>The same Record&#39;s &quot;created_at&quot; on the JavaScript side in ISO8601 format:</pre><pre>2020–07–01T02:32:21.580Z</pre><pre>Parse in JS:<br>new Date(“2020–07–01T02:32:21.580Z”)</pre><pre>//=&gt; Tue Jun 30 2020 19:32:21 GMT-0700 (Pacific Daylight Time)</pre><pre>Uh oh! We&#39;ve lost the offset and it thinks it&#39;s the previous day</pre><pre>new Date(&quot;2020-07-01T02:32:21.580Z&quot;).getDate()</pre><pre>//=&gt; 30</pre><pre>Fixed!</pre><pre>new Date(&quot;2020-07-01T02:32:21.580Z&quot;).getUTCDate()</pre><pre>//=&gt; 1</pre><p>We need to specify that instead of assuming local time, we want to calculate dates based on UTC so calling .getUTCDate gives us the correct day that is agnostic from timezones.</p><p>12. Now that our dates are properly parsed, we can check to see if the currentCell‘s freshly minted date value is equivalent to the “created_at” date for our User’s reported feelings.</p><p>13. Use a Ternary to increment either the satisfied or unsatisfied counts for that current day</p><p>14. Finally, we can run a check to choose the fill color of the currentCell based on comparing satisfiedCount and unsatisfiedCount. Let’s pop in a debugger and watch this baby work!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*zSjJDjeqp7XyQAMluEb_3Q.gif" /><figcaption>Stepping through the iterations to watch the calendar populate.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Conclusion</h3><p>WE MADE IT! This was really fun and challenging to build. I am particularly happy that I feel armed with a better understanding of how to work with dates in JavaScript. I have some refactors in my future, but I am pleased that it is working for now.</p><p>What is something you are proud of building? Any questions? Let me know in the comments!</p><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date">Date Constructor— MDN</a></li><li><a href="https://en.wikipedia.org/wiki/ISO_8601">ISO8601 — Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Coordinated_Universal_Time">Coordinated Universal Time — Wikipedia</a></li><li><a href="https://www.timeanddate.com/time/gmt-utc-time.html">GMT vs. UTC — Time and Date</a></li><li><a href="https://medium.com/@nitinpatel_20236/challenge-of-building-a-calendar-with-pure-javascript-a86f1303267d">Challenge of building a Calendar with Pure JavaScript </a>— <a href="https://medium.com/u/fae9d84f67cb">Nitin Patel</a></li><li><a href="https://svg2jsx.com/">SVGtoJSX</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6751b19a2d95" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/building-a-calendar-heatmap-with-svg-and-react-js-6751b19a2d95">Building a Calendar Heatmap with SVG and React.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with SVGs]]></title>
            <link>https://medium.com/dancing-syntax/working-with-svgs-758e8cb4e3f8?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/758e8cb4e3f8</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[svg-animation]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Sun, 26 Jul 2020 04:49:59 GMT</pubDate>
            <atom:updated>2020-10-20T08:11:36.809Z</atom:updated>
            <content:encoded><![CDATA[<h4>Dancing Syntax</h4><h3>Working with SVG</h3><h4>My first exploration.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SY1DL8nLZAgDNdf4D7S7oQ.jpeg" /><figcaption>Scalable Vector Graphics are powerful — Photo by <a href="https://unsplash.com/@pankajpatel">Pankaj Patel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>While working on my final project for Flatiron School, I had the opportunity to work with two EPIC designers for my project: <a href="https://medium.com/u/4d2e5b0cbc9f">Anna Wu</a> and <a href="https://medium.com/u/86339748ded5">Kendra Jenel</a>. They recommended that I export their designs from Figma as SVGs, a file type I have never worked with before….</p><p>Coooool, It’s time to learn something new!</p><h3>Introduction</h3><p>SVG was developed by the World Wide Web Consortium in 1999 and saw its official release in late 2001. SVGs are an Extensible Markup Language (XML) based graphic format for 2D images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Scalable Vector Graphics (SVG)</h3><h4>Vector vs. Raster</h4><p>To understand more about them, let’s look at a light comparison of image technologies.</p><p><strong>Raster</strong> images are built with pixels arranged on a grid, usually drawn left to right, and top to bottom. One issue here is that large raster image files are costly to store and load, which can lead to pages loading very slow. Additionally, raster graphics don’t scale very well at all. You can try this out by trying to scale up (resize) a JPG or PNG image. You’ll notice that your image lost a lot of quality in the process, a similar loss of quality occurs when scaling down.</p><p>In the gif below, we see a raster scan at work. The beam travels line by line, in the case of a raster image, drawing the pixels based on the images pixel data, if a pixel should be drawn, the beam is on, if not, the beam is off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*VATJ_WpNQOQ7YkzuaLftwA.gif" /><figcaption>Raster Scan at work. Source: <a href="https://web.cecs.pdx.edu/~jeske/litho/scanning.html">https://web.cecs.pdx.edu/~jeske/litho/scanning.html</a></figcaption></figure><p><strong>Vector</strong> images consist of coordinates placed on a cartesian plane, connected by lines and curves to form polygonal shapes and more. The coordinates mark where a vector path starts, the direction they go and ends. These paths have attributes that describe the fill color, stroke color, shape, thickness, and curve of the path.</p><p>In the example gif below, the beam is drawing based on the coordinates it was instructed to draw at.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*UqknTg30Z-9tV6L0EFkCoQ.gif" /><figcaption>A Vector Scan at work. Source: <a href="https://web.cecs.pdx.edu/~jeske/litho/scanning.html">https://web.cecs.pdx.edu/~jeske/litho/scanning.html</a></figcaption></figure><h4>SVG</h4><p>SVG is a markup language based on XML to represent vector images as code. Since they are a form of XML markup, they can be indexed and searched. This means that by including ARIA labels and roles, screen-readers can read what the file is from the browser.</p><p>Another benefit of the text XML is that and SVG can be edited in any text editor. Details can be easily added to or removed from vector images by simply adding or changing the values of a given attribute.</p><p>So far, the learning curve for what you can do with SVG seems pretty steep to my currently untrained eyes. I’ve read that you can do all sorts of things with them, including animation! SVGs are great for illustrations, user interfaces, and icons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EQgyT4AUjtmBAvD9TkAkQ.png" /></figure><h3>Examples:</h3><h4>SVGs can be created and edited programmatically.</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FJmclean01%2Fembed%2Fpreview%2FpogBNPB%3Fheight%3D600%26slug-hash%3DpogBNPB%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FJmclean01%2Fpen%2FpogBNPB&amp;image=https%3A%2F%2Fassets.codepen.io%2F3886515%2Finternal%2Fscreenshots%2Fpens%2FpogBNPB.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dfalse%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1595729878%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/49ff9130d6ade84198d866eea6f9e753/href">https://medium.com/media/49ff9130d6ade84198d866eea6f9e753/href</a></iframe><p>In this codepen, we are defining a &lt;svg&gt;&lt;/svg&gt; with an XML namespace, width, height, and version. The XML namespace is specifying that we will use SVG XML elements and attributes in our file.</p><p>Inside our, &lt;svg&gt;&lt;/svg&gt; we are defining a rectangle with&lt;rect&gt;&lt;/rect&gt; to render on the pen. The rectangle has x and y attributes for its position, width, and height for its size, a stroke attribute which defines the color to draw the rectangle, a transparent fill color for nothing inside the stroke’s lines, and a stroke-width attribute to specify how thick the lines will be. Copy this code in your own pen and play with these attributes to see how they affect the rectangle!</p><h4>SVGs can have events.</h4><p>If you open you the Javascript Pen, you’ll see some code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anRU7taDQX66e7JQMiy6Pg.png" /><figcaption>Javascript code</figcaption></figure><p>You should be able to click on the rectangle, toggling its inner fill color between green and transparent!</p><p>Depending on which Javascript library you use, working with events may be a little different than what you see in the codepen. However, from this example, we can imagine having all sorts of SVG icons that are clickable.</p><h4>SVGs can be animated.</h4><p>Remember how I said SVGs could be animated? It turns out those can be done programmatically too. I’m not sure how exactly to do that yet, but I found this really cool tool called <a href="https://www.svgator.com/">SVGator</a> that abstracts a lot of the SVG animation code into a GUI tool. You can use sample SVG from the library and upload your own SVGs. The tool allows you to view the properties of your SVG image and edit them. You can add keyframes, control the type of animation, and more!</p><p>With SVGator, I was able to turn this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIqyqBhQFOVGr3lLWOd1Kg.png" /><figcaption>Icon for my project. Beautifully crafted by Anna and Kendra.</figcaption></figure><p>Into this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VMnAbbORfjuK6yjpek3Zmg.gif" /><figcaption>Super cool animated SVG</figcaption></figure><p>My introduction to animation was in high school with Autodesk Maya, and I loved it so much. Working with SVG and learning what I have so far has been really fun. I hope this is useful to you beginning your own learning process.</p><p>Happy coding!</p><h3>Sources</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/SVG">MDN — SVG</a></li><li><a href="https://en.wikipedia.org/wiki/Vector_graphics">Vector Graphics — Wikipedia</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=758e8cb4e3f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dancing-syntax/working-with-svgs-758e8cb4e3f8">Working with SVGs</a> was originally published in <a href="https://medium.com/dancing-syntax">Dancing Syntax</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying unfamiliar code: ndarrays and get-pixels.]]></title>
            <link>https://medium.com/dancing-syntax/demystifying-unfamiliar-code-ndarrays-and-get-pixels-34e0db4ac7ce?source=rss-55c390e13e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/34e0db4ac7ce</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[Joshua Mclean]]></dc:creator>
            <pubDate>Mon, 29 Jun 2020 17:48:34 GMT</pubDate>
            <atom:updated>2020-09-14T02:04:06.054Z</atom:updated>
            <content:encoded><![CDATA[<h4>Dancing Syntax</h4><h3>Nth-Dimensional Arrays and Image Processing.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OSJMx_NwcTemBPl6" /><figcaption>Photo by <a href="https://unsplash.com/@codestorm?utm_source=medium&amp;utm_medium=referral">Safar Safarov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>About a month into the Flatiron School Bootcamp, a friend of mine gave me this advice:</p><p>“Learning to read code will help you become a better programmer.”</p><p>At first, I heard that and thought, “Yeah!” It made sense to me, but while working on labs, I came across some code that I struggled to make sense of:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06f4a60dffbf95a7ab539fc4070e5293/href">https://medium.com/media/06f4a60dffbf95a7ab539fc4070e5293/href</a></iframe><p>A function called rgbToHex, a pixel matrix, an npm package, some loops, hex codes, and a lot to do with arrays. Fascinating! At a high-level, data.js is loading a file into an npm package called get-pixels, that package is processing the data, which results in a nested array of hex codes. My brain was in overload! I wanted to understand, but so much was unfamiliar. Could I read my way into figuring this out?</p><p>After all, I didn’t need to try to understand it, it’s some helper code for the lab. The purpose of the lab was to learn how information flowed between components in React. The challenge was to finish implementing the functionality for an in-browser pixel drawing app.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FiGGetw8dPzlInd5ckF%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FiGGetw8dPzlInd5ckF&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FiGGetw8dPzlInd5ckF%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="215" frameborder="0" scrolling="no"><a href="https://medium.com/media/63627528567d1cdacba9ef5dc7405eef/href">https://medium.com/media/63627528567d1cdacba9ef5dc7405eef/href</a></iframe><p>Okay! Let’s move on, BUT WAIT… What about that code from earlier?</p><p>At first glance, I didn’t know what was going on, but transforming images into pixel data and rendering those pixels as divs seemed pretty bomb.com. With my friend’s advice in mind, Let’s pick it apart!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Get-Pixels</h3><p>Let’s start with the npm package! After taking a look at the documentation, I found out that <a href="https://www.npmjs.com/package/get-pixels">Get-Pixels</a> reads the pixel data from an image and returns the result as a <strong>ndarray (Nth-Dimensional Array)</strong>.</p><p>Specifically, it:</p><blockquote>“Returns An ndarray of pixels in raster order having shape equal to [width, height, channels].”</blockquote><p>Two things are new to me here: <strong>Raster order</strong> and <strong>ndarrays.</strong><br>After a quick search, I found out that Raster order describes the ordering of an image divided into rows of its pixels called scan lines.</p><p>In this context, get-pixels takes in an image, reads the pixel data from left-right and top-bottom, and then records that image data to a ndarray. With a console.log of the pixels returned, we can begin to see a piece of the multidimensional array and some information about it. More things to learn about!</p><pre>// console.log(&#39;got pixels&#39;, pixels)         line 9 in data.js<br>//=&gt; got pixels View3duint8 {<br>  data: Uint8Array(2500) [<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255,<br>    ... 2400 more items<br>  ],<br>  shape: [ 25, 25, 4 ],<br>  stride: [ 4, 100, 1 ],<br>  offset: 0<br>}</pre><p>Uint8 is shorthand for <em>unsigned 8bit integer</em>. That means (2⁸)-1, or 255. It’s commonly known as the value range for RGB color values: Red, Green, and Blue channels. Each channel has a value between 0–255, representing the intensity of its corresponding color. There’s also that sometimes hard to see alpha channel too, but that’s for opacity!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*nDvGZRgPeO2Eyn1PIw-bjA.gif" /><figcaption>Laughing cause I made a joke.</figcaption></figure><p>We also get the shape of this <strong>ndarray. </strong>That word can kiss it’s bold status goodbye because we’re about to learn about them!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Ndarray</h3><p>An Nth-Dimensional Array is a multidimensional array of items of the same type and size. The number of dimensions and items in the array are defined by the <strong>shape</strong>, positive integers that specify the sizes of each dimension. They are great for representing images, audio, matrices, strings, and other dimensional data.</p><p>Ndarrays are themselves a part of a Python package called <a href="https://www.w3resource.com/numpy/index.php">NumPy</a> — a library of code for scientific computing in Python. The library provides a variety of data types for integers and floats, the multidimensional array itself, and methods to operate, transform, and iterate on the ndarrays.</p><p>Get-Pixels uses <a href="https://github.com/scijs">sciJS</a>, a Javascript library that allows you to implement similar functionality to NumPy’s scientific computing.</p><p>Cool! Let’s visualize this. A Rubix Cube!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*gL4YfJxDh18X_e57yjhyvg.png" /><figcaption>A 3D array with a shape of (3, 3, 3), a Rubik’s cube!</figcaption></figure><p>Now in code, it is an array of 6 3x3 arrays:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Frepl.it%2F%40jmcleancoder%2FNaiveEquatorialInstances%3Flite%3Dtrue&amp;display_name=repl.it&amp;url=https%3A%2F%2Frepl.it%2F%40jmcleancoder%2FNaiveEquatorialInstances%3Flite%3Dtrue&amp;image=https%3A%2F%2Frepl.it%2Fpublic%2Fimages%2Freplit-logo-800x600.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=repl" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaa83f45119bad51e1176b3d1ad1cd7f/href">https://medium.com/media/aaa83f45119bad51e1176b3d1ad1cd7f/href</a></iframe><p>Okay, that was a ton of googling, drawing, and REPL fun y’all. Now we know a bit more about nd-arrays. With all of the knowledge gathered, we can figure out how data.js does all its magic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Cracking the Code</h3><p>Going back to that original console.log, we now know that this is a 3-Dimensional Array of RGB color values, It has a shape equal to its width, height, and channels. In this case [25W, 25H, 4Channels(RGBa)</p><pre>// console.log(&#39;got pixels&#39;, pixels)         line 9 in data.js<br>//=&gt; got pixels View3duint8 {<br>  data: Uint8Array(2500) [<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,<br>    255, 255, 255, 255,<br>    ... 2400 more items<br>  ],<br>  shape: [ 25, 25, 4 ],<br>  stride: [ 4, 100, 1 ],<br>  offset: 0</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f5db09c0b67bc54804093619e592a3a/href">https://medium.com/media/6f5db09c0b67bc54804093619e592a3a/href</a></iframe><p>We see the first function from the file takes in a single RGB value and converts that value to a hexadecimal string. If that string is only one character long, add a 0 to it.</p><pre>Number(255).toString(16) //=&gt; &quot;ff&quot; or &#39;red&#39; in hex.</pre><p>Now we can look at those fancy loops and derive what is happening:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10026d4a31a265256a59208b75f47919/href">https://medium.com/media/10026d4a31a265256a59208b75f47919/href</a></iframe><p>First, we traverse the height, then the width of the 3Darray with for loops. Each loop is set to terminate before it’s pointer gets to our width and height values from the shape.</p><pre>let row = [&#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;, &#39;#FFF&#39;]</pre><p>Declare a variable and assign it an array of white color hex codes. This array is forming a single line of white hex color pixels to begin our raster scan. We’re building a frame for our picture.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3844b1121b6a64197a44837a6fd9da2/href">https://medium.com/media/a3844b1121b6a64197a44837a6fd9da2/href</a></iframe><p>If we look closely at this line, you see that we are targeting each pixel element across the RGB channels, converting the values into hex code pieces, and including an octothorpe in the beginning. Then we push those codes onto the end of the row array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10026d4a31a265256a59208b75f47919/href">https://medium.com/media/10026d4a31a265256a59208b75f47919/href</a></iframe><p>Line 7–8: Once the loop reaches the end, push on another line of white hex colors, push the completed row into a container array, then start again at the next step down in our height loop. We continue building rows like this, <strong>mimicking the pattern of the raster scan </strong>building left-right, top-bottom.</p><p>One sort of optimization that we could make is making the loops terminate dynamically based on the shape value we have access to.</p><pre>for (let y = 0; y &lt; 25; y++)</pre><pre>change to:</pre><pre>for (let y = 0; y &lt; pixels.shape[0]; y++)</pre><pre>for (let x = 0; x &lt; 25; x++)</pre><pre>change to:</pre><pre>for (let x = 0; x &lt; pixels.shape[1]; x++)</pre><p>I said this is a -sort of- optimization because it is playing with fire. It’s great if you don’t precisely know the pixel dimensions of your image, it’s also terrible if your image has large pixel dimensions. Though, I’d argue that you would rarely use this method of processing a large image anyways, so have fun!</p><p>The completed array of hex values looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6ff688a4b98b5e643452049156f3577/href">https://medium.com/media/a6ff688a4b98b5e643452049156f3577/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFd4cpcJqT8EP69-TKkc-Q.png" /></figure><h3>Conclusion</h3><p>Whew! That’s long, I went ahead and processed a different image to bring you joy. There’s more code going on behind the scenes, but since you know about Raster order, I’m sure you can figure it out!</p><p>So what did we learn from all this? We learned about:</p><ol><li>multidimensional arrays</li><li>Two npm packages: get-pixels and scijs/ndarray</li><li>Raster scan order</li><li>A starting point for solving a Rubik’s cube algorithmically</li><li>Creating fun things with divs.</li><li>R<strong>eading and dissecting code that is unfamiliar to you is a great way to stretch your brain and get exposed to new information.</strong></li></ol><p>Enjoy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*9JtgMmznEQtdnaQOAxlEvg.gif" /></figure><h4>Sources:</h4><ol><li><a href="https://www.npmjs.com/package/get-pixels">npmJS: Get-Pixels</a></li><li><a href="https://en.wikipedia.org/wiki/Raster_scan#:~:text=In%20a%20raster%20scan%2C%20an,known%20as%20%22scan%20lines%22.&amp;text=This%20ordering%20of%20pixels%20by,order%2C%20or%20raster%20scan%20order.">Wikipedia: Raster Scan</a></li><li><a href="https://github.com/scijs/ndarray">Github: sciJs/ndarray library</a></li><li><a href="https://www.w3resource.com/numpy/index.php">W3Resource: NumPy</a></li><li><a href="https://www.w3resource.com/numpy/ndarray/index.php">W3Resource: ndarray</a></li><li><a href="https://www.w3schools.com/colors/colors_hexadecimal.asp">W3Schools: Hex Colors</a></li><li><a href="https://www.w3schools.com/colors/colors_rgb.asp">W3Schools: RGB Colors</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34e0db4ac7ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dancing-syntax/demystifying-unfamiliar-code-ndarrays-and-get-pixels-34e0db4ac7ce">Demystifying unfamiliar code: ndarrays and get-pixels.</a> was originally published in <a href="https://medium.com/dancing-syntax">Dancing Syntax</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>