<?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 Vivens Ndatinya on Medium]]></title>
        <description><![CDATA[Stories by Vivens Ndatinya on Medium]]></description>
        <link>https://medium.com/@vivens_n?source=rss-f13880ed8d58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QgRVYPQS2Aei-Rxx.jpeg</url>
            <title>Stories by Vivens Ndatinya on Medium</title>
            <link>https://medium.com/@vivens_n?source=rss-f13880ed8d58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:00:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vivens_n/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[Array Methods Which Every JS developer Must Master]]></title>
            <link>https://medium.com/@vivens_n/array-methods-which-every-js-developer-must-master-6963ad735489?source=rss-f13880ed8d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/6963ad735489</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Vivens Ndatinya]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 16:54:47 GMT</pubDate>
            <atom:updated>2020-03-12T16:54:47.266Z</atom:updated>
            <content:encoded><![CDATA[<p>Most applications deal with a list of values, which in JavaScript are often stored in an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>. In order to write clean code, it is imperative that we, JavaScript developers, master the methods which the Array.prototype provides and know when it is appropriate to use each of them. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">MDN</a> provides an extensive documentation for these Array methods. From my experience I&#39;ve come to love few of them for one main reason: they don&#39;t change the existing array but return a new array with the needed values. If you have been developing with JavaScript for so long you might be used to the traditional push and pop which manipulate and mutate the array, it should no longer be the case.</p><p>Since ES6, JavaScript has tremendously evolved, developers we must not stay behind but evolve with the language. Practicing and mastering these methods makes coding with Array in JavaScript much more fun.</p><p><strong>#1: map()</strong></p><p>map() is a higher-order method function (means a function that accepts another function as a parameter) that creates a <strong>new array</strong> populated with the results of calling the provided function on every element in the calling array.</p><p>const fruits = [&quot;apple&quot;, &quot;mango&quot;, &quot;orange&quot;, &quot;pear&quot;, &quot;pineapple&quot;];</p><p>// Create a new array with uppercased fruit names const array = fruits.map(fruit =&gt; fruit.toUpperCase()); console.log(array);</p><p>//output: [&quot;APPLE&quot;, &quot;MANGO&quot;, &quot;ORANGE&quot;, &quot;PEAR&quot;, &quot;PINEAPPLE&quot;]</p><p><strong>#2: filter()</strong></p><p>filter() is a higher-order method that creates a <strong>new array</strong> containing only the values which pass the test implemented by the provided predicate function.</p><p>const fruits = [&quot;apple&quot;, &quot;mango&quot;, &quot;orange&quot;, &quot;pear&quot;, &quot;pineapple&quot;];</p><p>// New array of fruits that start with the letter p</p><p>const array = fruits.filter(fruit =&gt; fruit.startsWith(&quot;p&quot;)); console.log(array); //output: [&quot;pear&quot;, &quot;pineapple&quot;]</p><p><strong>#3: find()</strong></p><p>find() method returns the first value in the array that satisfies the test provided by the predicate function parameter</p><p>const fruits = [&quot;apple&quot;, &quot;mango&quot;, &quot;orange&quot;, &quot;pear&quot;, &quot;pineapple&quot;];</p><p>// Find the fruit that begins with m</p><p>const array = fruits.find(fruit =&gt; fruit.startsWith(&quot;m&quot;)); console.log(array); //output: mango</p><p>Notice the different between filter and find; filter() returns a new array of filtered values while find() a single value.</p><p><strong>#4: every()</strong></p><p>every() method checks if all the array&#39;s values pass the test of the predicate function parameter; Its return value is a boolean value: true or false</p><p>const locations = [ { city: &quot;Kansas City&quot;, state: &quot;MO&quot; }, { city: &quot;Seattle&quot;, state: &quot;WA&quot; }, { city: &quot;Phoenix&quot;, state: &quot;&quot; }, { city: &quot;Miami&quot;, state: &quot;&quot; }, { city: &quot;Los Angeles&quot;, state: &quot;CA&quot; } ];</p><p>// Check every location has a state value const stateCheck = locations.every(location =&gt; location.state); console.log(stateCheck); //output: false</p><p><strong>#5: some()</strong></p><p>some() method tests if at least one value in the array satisfies the test of the predicate function parameter. Same as every() it always returns a Boolean value</p><p>// Check if some locations have state value const stateCheck = locations.every(location =&gt; location.state); console.log(stateCheck); //output: true</p><p><strong>#6: reduce()</strong></p><p>reduce() method, as its name implies, reduces the array to single value by executing the provided function parameter on every value in the array from left to right and storing the return value in an accumulator (result). Again reduce does not change the original array.</p><p>const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];</p><p>const sum = numbers.reduce((total, value) =&gt; total + value, 0); console.log(sum); //output: 55</p><p><strong>#7: sort()</strong></p><p>sort() method sorts the array&#39;s values in place either in the ascending order or in the descending order.</p><p>const fruits = [&quot;Banana&quot;, &quot;Orange&quot;, &quot;Apple&quot;, &quot;Mango&quot;]; console.log(fruits.sort()); //output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;, &quot;Orange&quot;]</p><p>It is important to note that by default sort() sorts the array&#39;s values as strings. For this reason, if numbers are sorted as strings, &quot;25&quot; is bigger than &quot;100&quot;, because &quot;2&quot; is bigger than &quot;1&quot;, and the sorting result for numbers will be incorrect.</p><p>The good news sort() accepts compare function parameter that can be used to address the issue.</p><p>const points = [40, 100, 1, 5, 25, 10]; const sortedPoints = points.sort(function(a, b){return a - b}); console.log(sortedPoints); //output: [1, 5, 10, 25, 40, 100]</p><p><strong>#8: concat()</strong></p><p>concat() method returns a new array containing this array joined with one or multiple other arrays.</p><p>const fruits1 = [&quot;apple&quot;, &quot;mango&quot;, &quot;orange&quot;, &quot;pear&quot;, &quot;pineapple&quot;];</p><p>const fruits2 = [&quot;kiwi&quot;, &quot;strawberry&quot;]; const fruits3 = fruits1.concat(fruits2); console.log(fruits3);</p><p>//output: [&quot;apple&quot;, &quot;mango&quot;, &quot;orange&quot;, &quot;pear&quot;, &quot;pineapple&quot;, &quot;kiwi&quot;, &quot;strawberry&quot;]</p><p><em>Note</em>: Another way to combine multiple arrays into one consists of using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">spread</a> operator, preferably you should choose to use spread over concat() because the spread syntax is more concise and easier to write. The only advantage of concat() is that takes both array and non-array values. The quick rule to choose is that you are dealing with arrays only, use spread; if there is the possibility of a non-array, use concat() for merging.</p><p>For conclusion, master the Array methods and have fun building.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6963ad735489" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Basic Concepts — 3 Conceptual Areas]]></title>
            <link>https://medium.com/@vivens_n/git-basic-concepts-3-conceptual-areas-7f88da4cd444?source=rss-f13880ed8d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f88da4cd444</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitflow]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Vivens Ndatinya]]></dc:creator>
            <pubDate>Tue, 10 Mar 2020 20:57:51 GMT</pubDate>
            <atom:updated>2020-03-10T20:57:51.233Z</atom:updated>
            <content:encoded><![CDATA[<h3>Git Basic Concepts — 3 Conceptual Areas</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*h_2lcIOh8tOWSyjP.png" /></figure><p>Git is a version control system that allows to record and manage file changes over time for your project; in other words Git takes snapshots of files and stores that information for you; as a result you can work on separate versions of a file in parallel, you can restore an earlier version of a file, you can view the history of the changes on your project… With these capabilities it is imperative that a proficient developer masters Git in order to increase her productivity.</p><p>At first glance, Git might seem to be a very complex system with lots of commands to cram in. The wrong way to learn Git is to memorize commands without taking the time to understand the fundamentals of Git and its big picture. For my first few months of using Git, I was in the same situation, but when I stepped back and invested time in learning the basic core concepts of Git and how it works, I was really surprised by its simplicity. I realized that commands are just mere tools; once you know what you are doing, it is easier to recall the right tool for the operation. That is why I decided to share my lessons on Git in this brief post.</p><p>Although Git a Distributed version control system, nearly every operation is local. Unlike most of VCS’s, Git has the entire history of the project/repository on the local machine, which makes Git operations fast and instantaneous without network latency. For example, to see the repository’s history, Git simply gets it directly from the repo’s local database without needing to fetch it from the server. Also if you want to see the changes between the current version of a file and the earlier one a month ago, Git can quickly look up the version of the file a month ago on your disk, then perform a fast difference calculation. Understanding how Git works locally is the key to master it. Once you understand Git’s local operations, it is much easier to grasp its distributed aspects.</p><p>First, assuming you already have git installed (you can find installation and setup documentation <a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">here</a>, it is important that you configure your Git username and email. when you make a commit, Git includes your username, email and timestamp in the history; this configuration helps track when changes were made and by who. You do this configuration with git config --global.</p><pre>git config --global user.name &quot;Vivens Ndatinya&quot; git config --global user.email &quot;vivens@mail.com&quot;</pre><p>Global config will be used for all the Git repos on your machine, and it is a one-time configuration. The --local option instead --global can be used if you ever want to set configuration just for one specific repository. Once you have completed the configuration, you can view it by running git config --list</p><p>Of course a Git repository must exist before you start doing Git operations.<br> To create a new Git repository on your machine, you run the git init command. This command creates an empty Git repository (a .git directory with the objects and template files for tracking changes). An initial HEAD file that references the HEAD of the master branch is also created. In this post we will be working on themaster branch automatically created by Git init , but it still important to invest time in learning Git branching</p><p>Now your Git repo is ready. Based on the nature of your project you might want some files not to be part of your project’s history; these might be build, log files … Happily, for this purpose Git supports a special file called gitignore which specifies intentionally untracked files to ignore. When deciding what files or directories to ignore Git checks the patterns specified by gitignore. These are a couple of the patterns:</p><ul><li>Wild cards can be used to ignore a category of files (eg: *.debug ignores all the files ending with .debug)</li><li>An entire directory can be ignored (eg: logs/ ignores all the files and subdirectories under the log directory)</li><li>To learn more on gitignore and the patterns you can visit <a href="https://git-scm.com/docs/gitignore">https://git-scm.com/docs/gitignore</a> or <a href="https://gitignore.io/">https://gitignore.io/</a></li></ul><p>Now let’s focus on the business of this post: Git’s basics and local operations: Git has 3 conceptual areas or states WORKING DIRECTORY, STAGING AREA and HISTORY.</p><ol><li><strong>WORKING DIRECTORY</strong></li></ol><ul><li>Once the repository is created with git init, you are in the WORKING DIRECTORY. The <em>working directory</em> corresponds to what you see in the file system; it is in the <em>working directory</em> state that you add, modify and delete files.</li><li>Let’s create a project called farm, and on the command line we run git init to initialize the repository. Next, we add a file called fruits.txt containing apples to the farm project. At this point running git status shows the state of the working directory, fruits.txt is listed under untracked files.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*TH8hjYr77IqkTY1D.png" /></figure><ul><li>The next step in the process is to stage the change (move it to the Staging Area)</li></ul><p><strong>2. STAGING AREA</strong></p><ul><li>By definition, the staging area is simply a cache of files you want to go into your next commit, which sometimes referred to as the INDEX. You might wonder: Is this extra step important? Suppose you’re working on two features, one of the features is finished, and the other still needs some work to be done; and before you clock out for the day and go home, you would like to make a commit, but you would not want to commit the parts of the second feature, which is in progress not done yet. In this situation, Git becomes your best friend, you stage the changes you know belong to feature #1 and commit them. Feature #1 is done while the changes for feature #2 are still in progress in your working directory waiting for you in the morning… Metaphorically the <em>staging area</em> is the reception desk at the library, you put the files there for the librarian to prepare for filing into the library.</li><li>Changes are staged from the working directory with the git add command. git add . adds all the working directory&#39;s new files and modifications; but you can also selectively stage just specific changes you want to be part of your next commit, which adds only those changes to the staging area. Eg: git add fruits.txt will specify stage the new fruits.txt. At point running git status shows that the changes have been staged.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*KFT8FtnPBeZhsAa_.png" /></figure><p>What’s next? Committing to the repo’s history</p><p><strong>3. HISTORY</strong></p><p>Once you understand these <strong>3 conceptual areas</strong> and how changes move from one state to the next, you can easily grasp some other essential Git operations that you will often need as part of your development workflow</p><h3>View and comparing changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*fCQs7Eeo8ndAj7AU.jpg" /></figure><ol><li>First, Git allows comparing differences between the Working Directory and Staging Area. This is accomplished by running the git diff command</li></ol><p>In the farmproject, let add mangoto the fruits.txtfile; git statusshows that the file has been changed, by running git diffwe see the details of the change</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYBr6wH0lPRk-FCtXbX6Mg.png" /></figure><p>2. Second, Git allows comparing changes between the Staging Area and History. This is accomplished by the git diff --staged command. Note the --staged option</p><p>In our farm project, let’s stage the fruits.txt change: git add fruits.txt Running git diff --stagedshows the difference between staging and the last commit&#39;s of history</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*aMykiOKsrSTNwGAc.png" /></figure><h3>Undoing Changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*pP3WLzloWKCOW34T.jpg" /></figure><p>Developers often need to undo changes and restore to an earlier version of a file. Git solves the problem of stressing about losing earlier changes; you can freely experiment with different solutions, design patterns before choosing what is best for the problem at hand. Again Git is the friend that offers the freedom to restore previous changes whenever you need to.</p><ol><li>First, we can undo a Working Directory change with what is in the Staging Area</li></ol><ul><li>git checkout -- filenamereplaces a file in the Working Areawith the staged version of the file. To the farmproject, let&#39;s make a change to the vegetables.txtby adding carrots</li></ul><p>git statusconfirms the change was made; We no longer want carrots, we run git checkout -- vegetables.txt</p><ul><li>Are you sure the change is discarded? git statusand git diffare your go-to detectives!</li></ul><p>Note: In the Working Directory You can only undo changes of the files that were previously staged</p><p>2. Second, we can undo a change in Staging Area with what is in History</p><ul><li>We override a staged change with what is in the last commit (HEAD) by running the command git reset HEAD filename</li><li>For thefarmproject, we decide to add asparagusto vegetables.txtand we&#39;ve already staged it. Oh! we realize we don&#39;t have the seeds to plant it and it must be removed.</li><li>Running the command git reset HEAD vegetables.txt</li><li>If we run git diff --staged , we see no difference</li><li>However the Working Directory still has aspargusin vegetables.txt; we can confirm this by running git diff</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1__smT5aBnED_-jnYgClXw.png" /></figure><p>3. Further: We can restore a file from a specific earlier commit. It is accomplished with git checkout &lt;commit hash&gt; -- filename</p><ul><li>Back to farmproject, let&#39;s add peachto fruits.txt</li><li>Now the Working Directory has been changed, let’s see the commits that have affected the fruits.txt</li><li>git log -- fruits.txt, we see and copy the hash for the first commit</li><li>git checkout &lt;SHA 1&gt; -- fruits.txt. This updates both the working directory and the staging area</li><li>When in doubt git statusis your best friend, always use it</li></ul><h3>Conclusion</h3><p>We discussed why understanding the 3 conceptual areas or states of of Git, Working Directory, Staging Area &amp; History, is the key to mastering the invaluable version control system. Based on this knowledge, you can grasp how to perform different Git Operations including viewing changes, comparing differences between the conceptual areas and undoing changes. Remember that Git commands are just mere tools; in whatever Git workflow if you understand the basic conceptual areas, you will know what you are doing and confidently choose the right command.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f88da4cd444" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>