<?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 William Lotosky on Medium]]></title>
        <description><![CDATA[Stories by William Lotosky on Medium]]></description>
        <link>https://medium.com/@wlotosky?source=rss-58db0f8270d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by William Lotosky on Medium</title>
            <link>https://medium.com/@wlotosky?source=rss-58db0f8270d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:16:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wlotosky/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[Random Functions Keep Popping Up.]]></title>
            <link>https://medium.com/@wlotosky/random-functions-keep-popping-up-602e8ae89b34?source=rss-58db0f8270d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/602e8ae89b34</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[William Lotosky]]></dc:creator>
            <pubDate>Thu, 18 May 2017 03:38:15 GMT</pubDate>
            <atom:updated>2017-05-18T03:42:19.409Z</atom:updated>
            <content:encoded><![CDATA[<p>In these first few days of learning JavaScript I’ve come across many situations where I’ve needed to select a random element from a group of many elements. Many of these problems led to me a solution that involved creating functions with some common themes.</p><h3>Math.random();</h3><p>The heart of the randomness in these functions comes from Math.random(). JavaScript contains an object called ‘Math’ that contains many methods one of which, Math.random(), has quickly become my favorite. This Math method takes no arguments and returns a pseudorandom number in the range (0 ≤ x &lt; 1). By passing Math.random() as an argument into one of: Math.floor(), Math.ceil() or Math.round() and multiplying that by an integer we can generate a random integer in a given range.</p><p>Math.floor() will always round down:</p><p><strong>(Math.floor( Math.random( ) * n ) );</strong></p><p><strong>returns an integer in the range (0 ≤ x ≥ n-1)</strong></p><p>Math.ceil() will always round up:</p><p><strong>(Math.ceil( Math.random( ) * n ) );</strong></p><p><strong>returns an integer in the range (1 ≤ x ≥ n)</strong></p><p>Math.round() will round up or down:</p><p><strong>(Math.round( Math.random( ) * n ) );</strong></p><p><strong>returns an integer in the range (0 ≤ x ≥ n)</strong></p><h3>Getting a random element from an array</h3><p>Arrays and random numbers work well together because we can access array elements by their numerical index. We can create a simple function to generate a random array index or array element using Math.floor().</p><pre>function getRandomIndexFromArray (array) {</pre><pre>     return Math.floor(Math.random() * array.length);<br>}</pre><p>this function will return an integer corresponding to a random index in the array given as an argument. The array.length property makes sure that the random number is no bigger than the highest index of the array. We can make a very similar function that returns a random element from any array.</p><pre>function getRandomElementFromArray (array) {</pre><pre>     var randomIndex = Math.floor(Math.random() * array.length);</pre><pre>     return array[randomIndex];</pre><pre>}</pre><p>This function, when passed an array, generates a random index just like the previous function. Additionally it uses the random index to return the corresponding element from the array. These functions are very general and can be used in many different situations.</p><h3>Rearranging an array in a random order</h3><p>Another recurring randomization task that can be solved with a fairly general function is rearranging the elements in an array in a random order.</p><pre>var array = [a, b, c, d, e, f]</pre><pre>function shuffleArrayInRandomOrder (array) {</pre><pre>     var randomizedArray = [];</pre><pre>     for (var i = array.length; i &gt; 0; i = i — 1) {</pre><pre>          var randomIndex = getRandomIndexFromArray(array);</pre><pre>          randomizedArray.push(array[randomIndex];</pre><pre>          array.splice(randomIndex, 1);</pre><pre>     }</pre><pre>     return randomizedArray;</pre><pre>}</pre><p>This function takes an array as an argument just as other functions. Firstly the function generates and empty array which will contain are randomized array. Next up is the for loop, which is the meat and potatoes of this function. By referencing our old getRandomIndexFromArray function we can now do two things:</p><p>1. Add a random element from our initial array to our new randomized array.</p><p>2. Remove that same element from our initial array.</p><p>This step is crucial because if we don’t remove the same object from the old array we could pick it multiple times.</p><p>3. The counter decrements by one and the process runs until the original array is empty i.e array.length = 0. Finally an array containing the same elements shuffled in a random order is returned.</p><p>I believe this method is very similar to what is called a “Fisher-Yates shuffle” or a “Knuth shuffle”, which is a good starting point for a Wikipedia binge into logic and sorting.</p><p>I hope these functions can help you in your programming and maybe get you to think about and use Math.random() more often.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=602e8ae89b34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Default Stylings for List Elements.]]></title>
            <link>https://medium.com/@wlotosky/default-stylings-for-list-elements-26b775f5b4ca?source=rss-58db0f8270d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b775f5b4ca</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[William Lotosky]]></dc:creator>
            <pubDate>Mon, 01 May 2017 01:33:00 GMT</pubDate>
            <atom:updated>2017-05-01T01:33:00.714Z</atom:updated>
            <content:encoded><![CDATA[<p>All HTML elements are given browser-specific default CSS properties. While default styles can be helpful and save you time by giving elements useful functionalities, other times these default properties can be cumbersome and need to be changed to give the element the desired look or positioning.</p><p>As a relatively green web-dev I’ve found that there are several elements whose default styles I need to change practically every time I use them. These elements are the: &lt;ul&gt;/&lt;ol&gt; and &lt;li&gt; tags.</p><p>The &lt;ul&gt; or unordered-list element takes the property “list-style-type”, which can be shortened as “list-style”, it’s default value is “disc”.</p><p>Here is an example of a list of different animals:</p><pre>&lt;ul&gt;<br>  &lt;li&gt;Cats&lt;/li&gt;<br>  &lt;li&gt;Dogs&lt;/li&gt;<br>  &lt;li&gt;Frogs&lt;/li&gt;<br>  &lt;li&gt;Hampsters&lt;/li&gt;<br>  &lt;li&gt;Gerbils&lt;/li&gt;<br> &lt;/ul&gt;</pre><p>Without adding any styles yourself the list will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/127/1*ysaKJoEG6Qrn3qqsQFSieQ.png" /></figure><p>Let’s take a look at some other values for list-style-type: lower-greek and lower-roman:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/115/1*otH4qzm3ODJB_W-L0ESE1g.png" /><figcaption>list-style-type: lower-greek</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/122/1*vNP_IOfN1q-_AQKdjQm3UQ.png" /><figcaption>list-style-type: lower-roman</figcaption></figure><p>You can even make your own custom list-style by passing an image file, like a .png or .svg instead of one the regular values.</p><pre>ul {<br>     list-style-image: url(https://medium.com/star.svg)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/1*PMX_qEOcDa4aVglRn2SbIg.png" /><figcaption>from the Mozilla Developer Network CSS resource (url below)</figcaption></figure><p><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Styling_lists">https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Styling_lists</a></p><p>Most of the of time, I’ve found that list elements aren’t use to present literal text lists, like our list of animals above. Rather they’re used to organize several repeating elements such as a list of links in a navigation or a series of images in a photo gallery.</p><p>In these instances we don’t want our list to have any sort of graphical flourish in front of all our list items. So we can style our list by changing the list-style-type property to none like so:</p><pre>&lt;ul&gt; {<br>     list-style-type: none;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/98/1*jHB4My37wXFDoPTaRUJgbg.png" /><figcaption>our list of animals with list-style-type: none</figcaption></figure><p>Lists also come with a default amount of padding-left, so we will need to remove that for many common list uses.</p><pre>&lt;ul&gt; {<br>     list-style-type: none;<br>     padding: 0;<br>}</pre><p>An unordered list on it’s own isn’t very useful it needs to filled with list items, which also carry their own default stylings that often need to be changed.</p><p>We can also effect the same stylistic changes above by styling the list-item elements directly. By default &lt;li&gt; elements have a default display value of list-item. What does this actually mean and how can we change it?</p><pre>&lt;li&gt; {<br>     display: inline-block;<br>}</pre><p>If we give our &lt;li&gt; elements a display value of something other than list-item like say inline-block it will remove the padding and bullet points all at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*EY0i1HIWl_6olnLQQogD2g.png" /></figure><p>Now this doesn’t look ideal for presenting our list of animals or any other actual list for that matter. However it is more useful for setting up a gallery, navigation or other more common uses of lists elements when building a website.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b775f5b4ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>