<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emilie Gervais</title>
    <description>The latest articles on DEV Community by Emilie Gervais (@emilie_gl).</description>
    <link>https://dev.to/emilie_gl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F49187%2F8b577318-398f-4613-a3b9-edca971467e4.png</url>
      <title>DEV Community: Emilie Gervais</title>
      <link>https://dev.to/emilie_gl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emilie_gl"/>
    <language>en</language>
    <item>
      <title>Server Error status codes</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Thu, 06 Feb 2020 21:44:51 +0000</pubDate>
      <link>https://dev.to/emilie_gl/server-error-status-codes-360o</link>
      <guid>https://dev.to/emilie_gl/server-error-status-codes-360o</guid>
      <description>&lt;p&gt;&lt;em&gt;Preface:&lt;/em&gt; A HTTP status code is issued from the server in response to a client's request made to the server. The five status code response classes are &lt;strong&gt;informational&lt;/strong&gt;, &lt;strong&gt;successful&lt;/strong&gt;, &lt;strong&gt;redirection&lt;/strong&gt;, &lt;strong&gt;client error&lt;/strong&gt; and &lt;strong&gt;server error&lt;/strong&gt;.&lt;/p&gt;










&lt;h2&gt;
  
  
  Server Error status codes
&lt;/h2&gt;

&lt;p&gt;Server error status codes indicate that the request was valid, but an error on the server is preventing its fulfillment. &lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;500 Internal Server Error&lt;/li&gt;
&lt;li&gt;501 Not Implemented&lt;/li&gt;
&lt;li&gt;502 Bad Gateway&lt;/li&gt;
&lt;li&gt;503 Service Unavailable&lt;/li&gt;
&lt;li&gt;504 Gateway Timeout&lt;/li&gt;
&lt;li&gt;505 HTTP Version Not Supported&lt;/li&gt;
&lt;li&gt;506 Variant Also Negotiates&lt;/li&gt;
&lt;li&gt;507 Insufficient Storage (WebDAV)&lt;/li&gt;
&lt;li&gt;508 Loop Detected (WebDAV)&lt;/li&gt;
&lt;li&gt;510 Not Extended&lt;/li&gt;
&lt;li&gt;511 Network Authentication Required&lt;/li&gt;
&lt;li&gt;598 Network Read Timeout Error&lt;/li&gt;
&lt;li&gt;599 Network Connect Timeout Error&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;500 Internal Server Error&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request can't be fulfilled due to an unexpected condition encountered by the server. This error response is a generic "catch-all" response, given when no more specific message is suitable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;500 Internal Server Error&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.1" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;501 Not Implemented&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request can't be fulfilled because the server does not support the functionality required to fulfill it. A &lt;code&gt;Retry-After&lt;/code&gt; header can also be sent to tell the requester when to check back to see if the functionality is supported by then. &lt;code&gt;501 Not Implemented&lt;/code&gt; is the appropriate response when the server does not recognize the request method and is incapable of supporting it for any resource. The only methods that servers are required to support (and therefore that must not return &lt;code&gt;501 Not Implemented&lt;/code&gt;) are &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;HEAD&lt;/code&gt;. If the server does recognize the method, but intentionally does not support it, the appropriate response is &lt;code&gt;405 Method Not Allowed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;501 Not Implemented&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;502 Bad Gateway&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be fulfilled because the server was acting as a gateway or a proxy and received an invalid response from the upstream server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;502 Bad Gateway&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.3" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;503 Service Unavailable&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be handled by the server because it is overloaded or down for maintenance. In other words, the server is not ready to handle the request. This response should be used for temporary conditions and the &lt;code&gt;Retry-After&lt;/code&gt; HTTP header should, if possible, contain the estimated time for the recovery of the service. Caching-related headers that are sent along with this response should be taken care of, as a &lt;code&gt;503 Service Unavailable&lt;/code&gt; status is often a temporary condition and responses shouldn't usually be cached.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;503 Service Unavailable&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.4" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;504 Gateway Timeout&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be fulfilled because the server was acting as a gateway or a proxy and it did not receive a response in time from the upstream server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;504 Gateway Timeout&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.5" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;505 HTTP Version Not Supported&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The request is using an HTTP version that is not supported by the server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;505 HTTP Version Not Supported&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.6.6" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;506 Variant Also Negotiates&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was made in the context of Transparent Content Negotiation, a protocol that enables a client to retrieve the best variant of a given resource, where the server supports multiple variants. The &lt;code&gt;506 Variant Also Negotiates&lt;/code&gt; status code indicates an internal server configuration error in which the chosen variant is itself configured to engage in content negotiation, so is not a proper negotiation endpoint.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;506 Variant Also Negotiates&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc2295#section-8.1" rel="noopener noreferrer"&gt;RFC 2295&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;507 Insufficient Storage&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be fulfilled because the server is unable to store the representation needed to complete it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;507 Insufficient Storage&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc4918#section-11.5" rel="noopener noreferrer"&gt;RFC 4918&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;508 Loop Detected&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The request cannot be fulfilled because the server detected an infinite loop while processing it. This status indicates that the entire operation failed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;508 Loop Detected&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc5842#section-7.2" rel="noopener noreferrer"&gt;RFC 5842&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;510 Not Extended&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was made in the context of the HTTP Extension Framework and cannot be fulfilled because one, many or all the described extensions are not supported by it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;510 Not Extended&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc2774#section-7" rel="noopener noreferrer"&gt;RFC 2774&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;511 Network Authentication Required&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was made without proper identification. The client needs to authenticate to gain network access. This status is not generated by origin servers, but by intercepting proxies that control access to the network. Network operators sometimes require some authentication, acceptance of terms, or other user interaction before granting access (for example in an internet café or at an airport). They often identify clients who have not done so using their Media Access Control (MAC) addresses.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;511 Network Authentication Required&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc6585#section-6" rel="noopener noreferrer"&gt;RFC 6585&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;598 Network Read Timeout Error&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; This status code is not specified in any RFCs, but is used by some HTTP proxies to signal a network read timeout behind the proxy to a client in front of the proxy.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;599 Network Connect Timeout Error&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; This status code is not specified in any RFCs, but is used by some HTTP proxies to signal a network connect timeout behind the proxy to a client in front of the proxy.&lt;/p&gt;










&lt;p&gt;Unofficial and customized non-standard responses defined by server softwares are not included in the list above. &lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml" rel="noopener noreferrer"&gt;Hypertext Transfer Protocol (HTTP) Status Code Registry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Client Error status codes</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Thu, 06 Feb 2020 21:34:15 +0000</pubDate>
      <link>https://dev.to/emilie_gl/client-error-status-codes-ne7</link>
      <guid>https://dev.to/emilie_gl/client-error-status-codes-ne7</guid>
      <description>&lt;p&gt;&lt;em&gt;Preface:&lt;/em&gt; A HTTP status code is issued from the server in response to a client's request made to the server. The five status code response classes are &lt;strong&gt;informational&lt;/strong&gt;, &lt;strong&gt;successful&lt;/strong&gt;, &lt;strong&gt;redirection&lt;/strong&gt;, &lt;strong&gt;client error&lt;/strong&gt; and &lt;strong&gt;server error&lt;/strong&gt;.&lt;/p&gt;










&lt;h2&gt;
  
  
  Client Error status codes
&lt;/h2&gt;

&lt;p&gt;Client Error status codes indicate that there was a problem with the request. It cannot be fulfilled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;400 Bad Request&lt;/li&gt;
&lt;li&gt;401 Unauthorized&lt;/li&gt;
&lt;li&gt;402 Payment Required&lt;/li&gt;
&lt;li&gt;403 Forbidden&lt;/li&gt;
&lt;li&gt;404 Not Found&lt;/li&gt;
&lt;li&gt;405 Method Not Allowed&lt;/li&gt;
&lt;li&gt;406 Not Acceptable&lt;/li&gt;
&lt;li&gt;407 Proxy Authentication Required&lt;/li&gt;
&lt;li&gt;408 Request Timeout&lt;/li&gt;
&lt;li&gt;409 Conflict&lt;/li&gt;
&lt;li&gt;410 Gone&lt;/li&gt;
&lt;li&gt;411 Length Required&lt;/li&gt;
&lt;li&gt;412 Precondition Failed&lt;/li&gt;
&lt;li&gt;413 Payload Too Large&lt;/li&gt;
&lt;li&gt;414 URI Too Long&lt;/li&gt;
&lt;li&gt;415 Unsupported Media Type&lt;/li&gt;
&lt;li&gt;416 Range Not Satisfiable&lt;/li&gt;
&lt;li&gt;417 Expectation Failed&lt;/li&gt;
&lt;li&gt;418 I'm a teapot&lt;/li&gt;
&lt;li&gt;421 Misdirect Request&lt;/li&gt;
&lt;li&gt;422 Unprocessable Entity (WebDAV)&lt;/li&gt;
&lt;li&gt;423 Locked (WebDAV)&lt;/li&gt;
&lt;li&gt;424 Failed Dependency (WebDAV)&lt;/li&gt;
&lt;li&gt;425 Too Early&lt;/li&gt;
&lt;li&gt;426 Upgrade Required&lt;/li&gt;
&lt;li&gt;428 Precondition Required&lt;/li&gt;
&lt;li&gt;429 Too Many Requests&lt;/li&gt;
&lt;li&gt;431 Request Header Fields Too Large&lt;/li&gt;
&lt;li&gt;451 Unavailable For Legal Reasons&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;400 Bad Request&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be understood by the server due to invalid syntax.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;400 Bad Request&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.1" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;401 Unauthorized&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be processed because it lacks valid authentication credentials for the target resource. This status is sent with a &lt;code&gt;WWW-Authenticate&lt;/code&gt; header that contains information on how to authorize correctly. This status is similar to &lt;code&gt;403 Forbidden&lt;/code&gt;, but in this case, authentication is possible.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;401 Unauthorized&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7235#section-3.1" rel="noopener noreferrer"&gt;RFC 7235&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;402 Payment Required&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request can not be processed until the client makes a payment. Originally it was created to enable digital cash or (micro) payment systems and would indicate that the requested content is not available until the client makes a payment. However, no standard use convention exists and different entities use it in different contexts. It is a nonstandard client error status response code that is reserved for future use.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;402 Payment Required&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;403 Forbidden&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was understood by the server but the server refuses to authorize it. This status is similar to &lt;code&gt;401 Unauthorized&lt;/code&gt; except that in this case, re-authenticating will make no difference. The access is permanently forbidden and tied to the application logic, such as insufficient rights to a resource.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;403 Forbidden&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.3" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;404 Not Found&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that can't be found by the server but may be available again in the future. Subsequent requests by the client are permissible. Links which lead to a 404 page are often called broken or dead links, and can be subject to &lt;code&gt;link rot&lt;/code&gt;. A &lt;code&gt;404 Not Found&lt;/code&gt; status code does not indicate whether the resource is temporarily or permanently missing. But if a resource is permanently removed, a &lt;code&gt;410 Gone&lt;/code&gt; should be used instead of a &lt;code&gt;404 Not Found&lt;/code&gt; status.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;404 Not Found&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.4" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;405 Method Not Allowed&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request method is known by the server but is not supported by the target resource. The server MUST generate an &lt;code&gt;Allow&lt;/code&gt; header field in a &lt;code&gt;405 Method Not Allowed&lt;/code&gt; response containing a list of the target resource's currently supported methods. For example, using &lt;code&gt;GET&lt;/code&gt; on a form which requires data to be presented via &lt;code&gt;POST&lt;/code&gt;, or using &lt;code&gt;PUT&lt;/code&gt; on a read-only resource. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;405 Method Not Allowed&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.5" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;406 Not Acceptable&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be fulfilled by the server. The server cannot produce a response matching the list of acceptable values defined in the request's content negotiation headers and is unwilling to supply a default representation. Content negotiation headers include: &lt;code&gt;Accept&lt;/code&gt;, &lt;code&gt;Accept-Charset&lt;/code&gt;, &lt;code&gt;Accept-Encoding&lt;/code&gt; and &lt;code&gt;Accept-Language&lt;/code&gt;. &lt;code&gt;406 Not Acceptable&lt;/code&gt; is rarely used: Servers usually ignore the relevant header and serve and actual page to the user. If a server returns such an error status, the body of the message should contain the list of the available representations of the resources, allowing the user to choose among them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;406 Not Acceptable&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.6" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;407 Proxy Authentication&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has not been applied because it lacks valid authentication credentials for a proxy server that is between the browser and the server that can access the requested resource. The client must first authenticate itself with the proxy. This status is sent with a &lt;code&gt;Proxy-Authenticate&lt;/code&gt; header that contains information on how to authorize correctly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;407 Proxy Authentication&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7235#section-3.2" rel="noopener noreferrer"&gt;RFC 7235&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;408 Request Timeout&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is taking too long. The server timed out waiting for it or decided to close the connection rather than continue waiting. The client MAY repeat the request without modifications at any later time. In the response, the server should send the close &lt;code&gt;Connection&lt;/code&gt; header field. This response is used much more since some browsers, like Chrome, Firefox 27+, and IE9, use HTTP pre-connection mechanisms to speed up surfing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;408 Request Timeout&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.7" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;409 Conflict&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request could not be processed because it is in conflict with the current state of the server. Conflicts are most likely to occur in response to a &lt;code&gt;PUT&lt;/code&gt; request. For example, you may get a &lt;code&gt;409 Conflict&lt;/code&gt; response when uploading a file which is older than the one already on the server resulting in a version control conflict.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;409 Conflict&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.8" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;410 Gone&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that is no longer available and will not be available again. Upon receiving a &lt;code&gt;410 Gone&lt;/code&gt; status code, the client should not request the resource again in the future. If you don't know whether this condition is temporary or permanent, a &lt;code&gt;404 Not Found&lt;/code&gt; status code should be used instead.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;410 Gone&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.9" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;411 Length Required&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request did not define &lt;code&gt;Content-Length&lt;/code&gt; header, which is required by the requested resource so it cannot be accepted by the server. By specification, when sending data in a series of chunks, the &lt;code&gt;Content-Length&lt;/code&gt; header is omitted and at the beginning of each chunk you need to add the length of the current chunk in hexadecimal format.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;411 Length Required&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.10" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;412 Precondition Failed&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has been denied access to the target resource. Per example, with conditional requests on methods other than &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;HEAD&lt;/code&gt; when the condition defined by the &lt;code&gt;If-Unmodified-Since&lt;/code&gt; or &lt;code&gt;If-None-Match&lt;/code&gt; headers is not fulfilled. In that case, the request, usually an upload or a modification of a resource, cannot be made and this error response is sent back.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;412 Precondition Failed&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7232#section-4.2" rel="noopener noreferrer"&gt;RFC 7232&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;413 Payload Too Large&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is larger than the limits defined by the server. The server might close the connection or return a &lt;code&gt;Retry-After&lt;/code&gt; header field if the condition is temporary.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;413 Payload Too Large&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.11" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;414 URI Too Long&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for an URI that is longer than what the server is willing to interpret. This is a rare condition that might occur when: A client has improperly converted a &lt;code&gt;POST&lt;/code&gt; request to a &lt;code&gt;GET&lt;/code&gt; request with more than ≈2 kB of submitted data; a client has descended into a loop of redirection or the server is under attack by a client attempting to exploit potential security holes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;414 URI Too Long&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.12" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;415 Unsupported Media Type&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is refued by the server because the payload format is unsurpported. The format problem might be due to the request's indicated &lt;code&gt;Content-Type&lt;/code&gt; or &lt;code&gt;Content-Encoding&lt;/code&gt;, or as a result of inspecting the data directly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;415 Unsupported Media Type&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.13" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;416 Range Not Satisfiable&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was made for a specific portion of the resource, but the server cannot supply it. The most likely reason is that the document doesn't contain such ranges, or that the &lt;code&gt;Range&lt;/code&gt; header value, though syntactically correct, doesn't make sense. The &lt;code&gt;416 Range Not Satisfiable&lt;/code&gt; response message contains a &lt;code&gt;Content-Range&lt;/code&gt; indicating an unsatisfied range (that is a &lt;code&gt;'*'&lt;/code&gt;) followed by a &lt;code&gt;'/'&lt;/code&gt; and the current length of the resource. For example: &lt;code&gt;Content-Range: bytes */12777&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;416 Range Not Satisfiable&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7233#section-4.4" rel="noopener noreferrer"&gt;RFC 7233&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;417 Expectation Failed&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has requirements in its &lt;code&gt;Expect&lt;/code&gt; header that the server can't meet.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;417 Expectation Failed&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.14" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;418 I'm a Teapot&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request wants the server the brew coffee, but the server refuses because it is a teapot. This error is a reference to Hyper Text Coffee Pot Control Protocol which was an April Fools' joke in 1998.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;418 I'm a Teapot&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc2324#section-2.3.2" rel="noopener noreferrer"&gt;RFC 2324&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;421 Misdirect Request&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;421 Misdirect Request&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7540#section-9.1.2" rel="noopener noreferrer"&gt;RFC 7540&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;422 Unprocessable Entity&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is understood by the server but the server is unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed, but semantically erroneous, XML instructions. The client should not repeat this request without modification.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;422 Unprocessable Entity&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc4918#section-11.2" rel="noopener noreferrer"&gt;RFC 7918&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;423 Locked&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is trying to access a locked resource. This response SHOULD contain an appropriate precondition or postcondition code, such as &lt;code&gt;lock-token-submitted&lt;/code&gt; or &lt;code&gt;no-conflicting-lock&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;423 Locked&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc4918#section-11.3" rel="noopener noreferrer"&gt;RFC 4918&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;424 Failed Dependency&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request failed due to failure of a previous request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;424 Failed Dependency&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc4918#section-11.4" rel="noopener noreferrer"&gt;RFC 4918&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;425 Too Early&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is considered one that might be replayed and the server is unwilling to risk processing it for security reasons. Replayed requests create the potential for a replay attack.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;425 Too Early&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc8470#section-5.2" rel="noopener noreferrer"&gt;RFC 8470&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;426 Upgrade Required&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request cannot be processed using the current protocol, but the server is willing to process it after the client upgrades to a different protocol. The server sends an &lt;code&gt;Upgrade&lt;/code&gt; header with this response to indicate the required protocols.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;426 Upgrade Required&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.15" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;428 Precondition Required&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is not conditional and the server requires that it be conditional: A required precondition header, such as &lt;code&gt;If-Match&lt;/code&gt;, is missing. When a precondition header is not matching the server side state, the response should be &lt;code&gt;412 Precondition Failed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;428 Precondition Required&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc6585#section-3" rel="noopener noreferrer"&gt;RFC 6585&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;429 Too Many Requests&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The request is one of too many sent by the user in a given amount of time (\"rate limiting\") Intended for use with rate limiting schemes. A &lt;code&gt;Retry-After&lt;/code&gt; header might be included to this response indicating how long to wait before making a new request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;429 Too Many Requests&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc6585#section-4" rel="noopener noreferrer"&gt;RFC 6585&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;431 Request Header Fields Too Large&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request's HTTP headers are too long, so the server refuses to process it. 431 can be used when the total size of request headers is too large, or when a single header field is too large. To help those running into this error, indicate which of the two is the problem in the response body — ideally, also include which headers are too large. This lets users attempt to fix the problem, such as by clearing their cookies. Servers will often produce this status if: The &lt;code&gt;Referer&lt;/code&gt; URL is too long or if there are too many &lt;code&gt;Cookies&lt;/code&gt; sent in the request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;431 Request Header Fields Too Large&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc6585#section-5" rel="noopener noreferrer"&gt;RFC 6585&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;451 Unavailable For Legal Reasons&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that is not available due to legal reasons. Per example, a web page for which legal action has been issued.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;451 Unavailable For Legal Reasons&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7725#section-3" rel="noopener noreferrer"&gt;RFC 7725&lt;/a&gt;.&lt;/p&gt;










&lt;p&gt;Unofficial and customized non-standard responses defined by server softwares are not included in the list above. &lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml" rel="noopener noreferrer"&gt;Hypertext Transfer Protocol (HTTP) Status Code Registry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Redirection status codes</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Thu, 06 Feb 2020 21:13:02 +0000</pubDate>
      <link>https://dev.to/emilie_gl/redirection-status-codes-1id9</link>
      <guid>https://dev.to/emilie_gl/redirection-status-codes-1id9</guid>
      <description>&lt;p&gt;&lt;em&gt;Preface:&lt;/em&gt; A HTTP status code is issued from the server in response to a client's request made to the server. The five status code response classes are &lt;strong&gt;informational&lt;/strong&gt;, &lt;strong&gt;successful&lt;/strong&gt;, &lt;strong&gt;redirection&lt;/strong&gt;, &lt;strong&gt;client error&lt;/strong&gt; and &lt;strong&gt;server error&lt;/strong&gt;.&lt;/p&gt;










&lt;h2&gt;
  
  
  Redirection status codes
&lt;/h2&gt;

&lt;p&gt;Redirection status codes are returned when a new resource has been substituted for the requested resource. To complete the request, further action must be taken.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;300 Multiple Choices&lt;/li&gt;
&lt;li&gt;301 Moved Permanently&lt;/li&gt;
&lt;li&gt;302 Found&lt;/li&gt;
&lt;li&gt;303 See Other&lt;/li&gt;
&lt;li&gt;304 Not Modified&lt;/li&gt;
&lt;li&gt;305 Use Proxy&lt;/li&gt;
&lt;li&gt;306 (Unused)&lt;/li&gt;
&lt;li&gt;307 Temporary Redirect&lt;/li&gt;
&lt;li&gt;308 Permanent Redirect&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;300 Multiple Choices&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has more than one possible response. The user-agent or client should choose one of them. There is no standardized way of choosing one of the responses, but HTML links to the possibilities are recommended so the user can pick. For example, this code could be used to present multiple video format options, to list files with different filename extensions, or to suggest word-sense disambiguation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;300 Multiple Choices&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;301 Moved Permanently&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that has moved permanently. Its new URL is given in the response.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;301 Moved Permanently&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;302 Found&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource with a URI that has been changed temporarily. Further changes in the URI might be made in the future. The current URI should be used by the client in future requests.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;302 Found&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.3" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;303 See Other&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that can be found at another URI using a &lt;code&gt;GET&lt;/code&gt; method. When received in response to a &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt; or &lt;code&gt;DELETE&lt;/code&gt;, it should assumed that the server has received the data and the redirect should be issued with a separate &lt;code&gt;GET&lt;/code&gt; message.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;303 See Other&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.4" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;304 Not Modified&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for resource that hasn't been modified since the last time the client accessed it, so the client can continue to use the same cached version of the response.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;304 Not Modified&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7232#section-4.1" rel="noopener noreferrer"&gt;RFC 7232&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;305 Use Proxy&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;*&lt;br&gt;
Definition:* The request is looking for a resource that must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;305 Use Proxy&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.5" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;306 (Unused)&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; This response code is no longer used; it is just reserved. It was used in a previous version of the HTTP/1.1 specification.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;306 (Unused)&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.6" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;307 Temporary Redirect&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request is looking for a resource that is currently redirected. The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request. Future requests can still use the original URI. &lt;code&gt;307 Temporary Redirect&lt;/code&gt; has the same semantics has the &lt;code&gt;302 Found&lt;/code&gt; response code, with the exception that the user agent must not change the HTTP method used: If a &lt;code&gt;POST&lt;/code&gt; was used in the first request, a &lt;code&gt;POST&lt;/code&gt; must be used in the second request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;307 Temporary Redirect&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.4.7" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;308 Permanent Redirect&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; This means that the resource is now permanently located at another URI, specified by the &lt;code&gt;Location:&lt;/code&gt; HTTP Response header. This has the same semantics as the &lt;code&gt;301 Moved Permanently&lt;/code&gt; HTTP response code, with the exception that the user agent must not change the HTTP method used: If a &lt;code&gt;POST&lt;/code&gt; was used in the first request, a &lt;code&gt;POST&lt;/code&gt; must be used in the second request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;308 Permanent Redirect&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7538#section-3" rel="noopener noreferrer"&gt;RFC 7538&lt;/a&gt;.&lt;/p&gt;










&lt;p&gt;Unofficial and customized non-standard responses defined by server softwares are not included in the list above. &lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml" rel="noopener noreferrer"&gt;Hypertext Transfer Protocol (HTTP) Status Code Registry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Successful status codes</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Thu, 06 Feb 2020 21:01:28 +0000</pubDate>
      <link>https://dev.to/emilie_gl/successful-status-codes-3jm</link>
      <guid>https://dev.to/emilie_gl/successful-status-codes-3jm</guid>
      <description>&lt;p&gt;&lt;em&gt;Preface:&lt;/em&gt; A HTTP status code is issued from the server in response to a client's request made to the server. The five status code response classes are &lt;strong&gt;informational&lt;/strong&gt;, &lt;strong&gt;successful&lt;/strong&gt;, &lt;strong&gt;redirection&lt;/strong&gt;, &lt;strong&gt;client error&lt;/strong&gt; and &lt;strong&gt;server error&lt;/strong&gt;.&lt;/p&gt;










&lt;h2&gt;
  
  
  Successful status codes
&lt;/h2&gt;

&lt;p&gt;Successful status codes are returned when the browser request was successfully received, understood and processed by the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;200 OK&lt;/li&gt;
&lt;li&gt;201 Created&lt;/li&gt;
&lt;li&gt;202 Accepted&lt;/li&gt;
&lt;li&gt;203 Non-Authoritative Information&lt;/li&gt;
&lt;li&gt;204 No Content&lt;/li&gt;
&lt;li&gt;205 Reset Content&lt;/li&gt;
&lt;li&gt;206 Partial Content&lt;/li&gt;
&lt;li&gt;207 Multi-Status (WebDAV)&lt;/li&gt;
&lt;li&gt;208 Already Reported (WebDAV)&lt;/li&gt;
&lt;li&gt;226 IM Used&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;200 OK&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has succeeded. Its response is cacheable. The meaning of this response depends on the HTTP request method the server received: For &lt;code&gt;GET&lt;/code&gt; requests, the resource has been fetched and is transmitted in the message body; for &lt;code&gt;HEAD&lt;/code&gt; requests, the entity headers are in the message body; for &lt;code&gt;POST&lt;/code&gt; requests, the resource describing the result of the action is transmitted in the message body; for &lt;code&gt;TRACE&lt;/code&gt; requests, the message body contains the request message as received by the server. For &lt;code&gt;PUT&lt;/code&gt; and &lt;code&gt;DELETE&lt;/code&gt; requests, a successful request is often not a &lt;code&gt;200&lt;/code&gt;, but a &lt;code&gt;204 No Content&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;200 OK&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.1" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;201 Created&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has been fulfilled and resulted in a new resource being created. Successful creation occurred (via either &lt;code&gt;POST&lt;/code&gt; or &lt;code&gt;PUT&lt;/code&gt;). The new resource is returned in the body of the message, its location being either the URL of the request, or the content of the Location header.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;201 Created&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;202 Accepted&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has been accepted for processing, but the processing has not been completed. It is non-committal, meaning that there is no way for the HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;202 Accepted&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.3" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;2013 Non-Authoritative Information&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was successful but is returning a modified version of the origin's response resulting in an enclosed payload that has been modified by a transforming proxy from that of the origin server's &lt;code&gt;200 OK&lt;/code&gt; response. The &lt;code&gt;203 Non-Authoritative Information&lt;/code&gt; response is similar to the value &lt;code&gt;214 Transformation Applied&lt;/code&gt; of the &lt;code&gt;Warning&lt;/code&gt; header code, which has the additional advantage of being applicable to responses with any status code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2013 Non-Authoritative Information&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.5" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;204 No Content&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has succeeded, but the client doesn't need to go away from its current page. This response is cacheable by default and includes an &lt;code&gt;ETag&lt;/code&gt; header. The common use case is to return &lt;code&gt;204 No Content&lt;/code&gt; as a result of a &lt;code&gt;PUT&lt;/code&gt; request, updating a resource, without changing the current content of the page displayed to the user. If the resource is created, &lt;code&gt;201 Created&lt;/code&gt; is returned instead. If the page should be changed to the newly updated page, the &lt;code&gt;200 OK&lt;/code&gt; should be used instead.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;204 No Content&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.5" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;205 Reset Content&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request was successfully processed by the server, but is not returning any content. Similar to &lt;code&gt;204 No Content&lt;/code&gt;, but lets the client know that it should reset the document view.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;205 Reset Content&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.3.6" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;206 Partial Content&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has succeeded, but the server is delivering only part of the resource due to a &lt;code&gt;Range&lt;/code&gt; header sent by the client. If there is only one range, the &lt;code&gt;Content-Type&lt;/code&gt; of the whole response is set to the type of the document, and a &lt;code&gt;Content-Range&lt;/code&gt; is provided. If several ranges are sent back, the &lt;code&gt;Content-Type&lt;/code&gt; is set to &lt;code&gt;multipart/byteranges&lt;/code&gt; and each fragment covers one range, with &lt;code&gt;Content-Range&lt;/code&gt; and &lt;code&gt;Content-Type&lt;/code&gt; describing it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;206 Partial Content&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7233#section-4.1" rel="noopener noreferrer"&gt;RFC 7233&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;207 Multi-Status (WebDAV)&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has succeeded and the body of the server's response is by default an XML message which can contain a number of separate responses codes, depending on how many sub-requests were made. Useful for situations where multiple status codes might be appropriate.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;207 Multi-Status (WebDAV)&lt;/code&gt; is defined in &lt;a href="https://www.iana.org/go/rfc4918" rel="noopener noreferrer"&gt;RFC 4918&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;208 Already Reported (WebDAV)&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has succeeded and contains a collection: Only one element will be reported with a &lt;code&gt;200 OK&lt;/code&gt; status. The others will be reported with a &lt;code&gt;208&lt;/code&gt; status inside the response element &lt;code&gt;&amp;lt;dav:propstat&amp;gt;&lt;/code&gt; to avoid repeatedly enumerating the internal members of multiple bindings to the same collection.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;208 Already Reported (WebDAV)&lt;/code&gt; is defined in &lt;a href="https://www.iana.org/go/rfc5842" rel="noopener noreferrer"&gt;RFC 5842&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;226 IM Used&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The request has succeeded and the response sent by the server is a representaiton of the result of one or more instance-manipulations applied to the current instance.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;226 IM Used&lt;/code&gt; is defined in &lt;a href="https://www.iana.org/go/rfc3229" rel="noopener noreferrer"&gt;RFC 3229&lt;/a&gt;.&lt;/p&gt;










&lt;p&gt;Unofficial and customized non-standard responses defined by server softwares are not included in the list above. &lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml" rel="noopener noreferrer"&gt;Hypertext Transfer Protocol (HTTP) Status Code Registry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Informational status codes</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Thu, 06 Feb 2020 19:43:20 +0000</pubDate>
      <link>https://dev.to/emilie_gl/informational-status-codes-4hgk</link>
      <guid>https://dev.to/emilie_gl/informational-status-codes-4hgk</guid>
      <description>&lt;p&gt;&lt;em&gt;Preface:&lt;/em&gt; A HTTP status code is issued from the server in response to a client's request made to the server. The five status code response classes are &lt;strong&gt;informational&lt;/strong&gt;, &lt;strong&gt;successful&lt;/strong&gt;, &lt;strong&gt;redirection&lt;/strong&gt;, &lt;strong&gt;client error&lt;/strong&gt; and &lt;strong&gt;server error&lt;/strong&gt;.&lt;/p&gt;










&lt;h2&gt;
  
  
  Informational status codes
&lt;/h2&gt;

&lt;p&gt;Informational status codes indicate that the request initiated by the browser was received and is continuing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;100 Continue&lt;/li&gt;
&lt;li&gt;101 Switching Protocols&lt;/li&gt;
&lt;li&gt;102 Processing&lt;/li&gt;
&lt;li&gt;103 Early Hints&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;100  Continue&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has been received and has not yet been rejected by the server. The server intends on sending a final response once the request has been completed meaning that the server has received the request headers and client can now proceed to send the request body. To have a server check the request's headers, a client must send &lt;code&gt;Expect: 100-continue&lt;/code&gt; as a header in its initial request and receive a &lt;code&gt;100 Continue&lt;/code&gt; status code in response before sending the body.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;100  Continue&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.2.1" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;101 Switching Protocols&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has asked the server to switch protocols. The server response indicates that it is switching protocol as requested. In this response, the server includes an &lt;code&gt;Upgrade&lt;/code&gt; response header to indicate the protocol it switched to.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;101 Switching Protocols&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.2.2" rel="noopener noreferrer"&gt;RFC 7231&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;102 Processing&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The request has been received and is being processed by the server, but no response is available yet. In the meantime, this response prevents the client from timing out and assuming the request was lost.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;102 Processing&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc2518#page-59" rel="noopener noreferrer"&gt;RFC 2518&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;103 Early Hints&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Definition:&lt;/em&gt; The server is likely to send a final response with the header fields included in the informational response. Mainly intended to be used with the &lt;code&gt;Link&lt;/code&gt; header to allow the user agent to start preloading resources while the server is still preparing a response.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;103 Early Hints&lt;/code&gt; is defined in &lt;a href="https://tools.ietf.org/html/rfc8297" rel="noopener noreferrer"&gt;RFC 8297&lt;/a&gt;.&lt;/p&gt;










&lt;p&gt;Unofficial and customized non-standard responses defined by server softwares are not included in the list above. &lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml" rel="noopener noreferrer"&gt;Hypertext Transfer Protocol (HTTP) Status Code Registry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Notes on algorithms</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Fri, 10 Jan 2020 13:47:45 +0000</pubDate>
      <link>https://dev.to/emilie_gl/notes-on-algorithms-36pi</link>
      <guid>https://dev.to/emilie_gl/notes-on-algorithms-36pi</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/kPRA0W1kECg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I'm doing &lt;a href="https://www.edx.org/course/cs50s-introduction-to-computer-science" rel="noopener noreferrer"&gt;CS50: Introduction to Computer Science&lt;/a&gt; on &lt;a href="https://www.edx.org" rel="noopener noreferrer"&gt;edx.org&lt;/a&gt;. I find it's a great way to review what I learn by completing, rewriting and sharing some of my notes. &lt;/p&gt;

&lt;p&gt;Note: Big O notation can be though of “on the order of” and it represents the running time of an algorithm. In the C examples, &lt;code&gt;n&lt;/code&gt; is equivalent to &lt;code&gt;sizeof(arr)/sizeof(arr[0])&lt;/code&gt; which translates in JavaScript to &lt;code&gt;arr.length&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Week 3 is about algorithms. 😺&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linear Search&lt;/li&gt;
&lt;li&gt;Binary Search&lt;/li&gt;
&lt;li&gt;Bubble Sort&lt;/li&gt;
&lt;li&gt;Selection Sort&lt;/li&gt;
&lt;li&gt;Insertion Sort&lt;/li&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;Merge Sort&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Linear Search &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To iterate across the array from left to right searching for a target element.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repeat, starting at the first element:
    If the element is the target element, stop
    Else, move to the next element
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For i from 0 to n–1
    If i'th element is target_element
        Return true
Return false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;linearSearch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linear Search algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to look through the entire array of &lt;code&gt;n&lt;/code&gt; elements in the case where the target element is the last one or it is not in the array. &lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The target element is the 1st element. &lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(1)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Binary Search &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To find the target element by reducing the search area by half each time. Make sure the array on which the binary search algorithm is used on is sorted, else it's impossible to make assumptions about its content.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repeat until the (sub)array is of size 0:
    Calculate the middle point of the current (sub)array
    If the target element is the middle element, stop
    Else if it's less than the middle: 
        End point is now just to the left of the current middle, repeat
    Else if it's greater than the middle: 
        Start point is now just to the right of the current middle, repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If no items
    Return false
If middle item is target_element
    Return true
Else if target_element &amp;lt; middle item
    Update end point
    Search left half
Else if target_element &amp;gt; middle item
    Update start point
    Search right half
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example (recursive):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="c1"&gt;// instead of (start+end)/2 to avoid overflow&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example (recursive):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;binarySearch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Binary Search algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to divide a list of &lt;code&gt;n&lt;/code&gt; elements in half repeatedly to find the target element because the target is found at the end of the last division or it is not in the array.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(log n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The target element is at midpoint of the array, so we can stop searching immediately after we start.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(1)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bubble Sort &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To sort in a bubbling way: move higher values towards the right of the array and lower values, towards the left.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set swap counter to a non-zero value
Repeat until the swap counter is equal to 0:
    Reset swap counter to 0
    Look at each adjacent pair:
        If two adjacent elements are not in order:
            Swap them
            Add one to the swap counter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repeat until no swaps
    For i from 0 to n–2
        If i'th and i+1'th elements out of order
            Swap them
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bubbleSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
                &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
                &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;bubbleSort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
                &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
                &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because comparing the &lt;code&gt;i&lt;/code&gt;th and &lt;code&gt;i+1&lt;/code&gt;th element, the sorting only needs to go up to &lt;code&gt;n-2&lt;/code&gt; for &lt;code&gt;i&lt;/code&gt; before swapping the two elements if they're out of order. Knowing the largest &lt;code&gt;n-1&lt;/code&gt; elements will have bubbled to the right, the sorting can stop after &lt;code&gt;n-1&lt;/code&gt; passes.&lt;br&gt;
When re-going through the array, only consider the unsorted elements.&lt;br&gt;
When the swap counter remains at &lt;code&gt;0&lt;/code&gt;, there is nothing else to swap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bubble sort algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to bubble each of the elements all the way across the array because the array is in reverse order. Since it's only possible to fully bubble one element into its sorted position per pass, the sorting must happen &lt;code&gt;n&lt;/code&gt; times.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(n²)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The array is already perfectly sorted, resulting in no swapping on the first pass.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Selection Sort &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To find the smallest unsorted element and add it to the end of the sorted list. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repeat until there is no unsorted elements remaining:
    Search unsorted part of data to find the smallest value
    Swap the found value with the first element of the unsorted part
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For i from 0 to n–1
    Find smallest item between i'th item and last item
    Swap smallest item with i'th item
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;selectionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="n"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;selectionSort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Selection sort algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to repeat the sorting process &lt;code&gt;n&lt;/code&gt; times to iterate each of the &lt;code&gt;n&lt;/code&gt; elements of the array to find the smallest unsorted element and sort it. Only one element gets sorted on each pass.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(n²)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The same as the worst case scenario as there is no way to guarantee the array is sorted until the sorting process iterates over all of the elements of the array.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(n²)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Insertion Sort &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To build a sorted array in place; shifting elements out of the way to make room if necessary as the array is being built. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Call the first element of the array sorted
Repeat until all elements are sorted:
    Insert next unsorted item into sorted part shifting the required number of items
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For i from 1 to n–1
    Insert next unsorted item into sorted part shifting i items
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
            &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
            &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;insertionSort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
            &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
            &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Insertion sort algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to shift each of the &lt;code&gt;n&lt;/code&gt; elements from &lt;code&gt;n&lt;/code&gt; positions each time to make an insertion because the array is in reverse order.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(n²)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The array is already sorted. Only gotta keep moving between unsorted and sorted elements as we iterate over each of them.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Recursion &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To code &lt;em&gt;elegantly&lt;/em&gt;. 🌹&lt;/p&gt;

&lt;p&gt;Recursion is related to how an algorithm or a function is implemented, it isn't an algorithm itself.&lt;/p&gt;

&lt;p&gt;A recursive function invokes itself as part of its execution.&lt;/p&gt;

&lt;p&gt;Detailed example using the factorial function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;n!&lt;/em&gt; is defined over all positive integers&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;n!&lt;/em&gt; equals all of the positive integers less than or equal to &lt;em&gt;n&lt;/em&gt;, multiplied together&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;n!&lt;/em&gt; as &lt;code&gt;fact(n)&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fact(1) = 1
fact(2) = 2 * 1
fact(3) = 3 * 2 * 1
…
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fact(1) = 1
fact(2) = 2 * fact(1)
fact(3) = 3 * fact(2)
…
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The basis for a recursive definition of the factorial function:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fact(n) = n * fact(n-1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Recursive function has two cases that can apply given any input:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Base case:&lt;/strong&gt; terminates the recursive process when triggered&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursive case:&lt;/strong&gt; where the recursion happens
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int fact(int n) 
{
    // base case
    if (n == 1)
        return 1;
    // recursive case
    else
        return n * fact(n-1);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;There can be multiple base cases.&lt;/strong&gt;&lt;br&gt;
Example the fibonacci number sequence where: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1st element is &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;2nd element is &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n&lt;/code&gt;th element is the sum of &lt;code&gt;(n-1)+(n-2)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;There can be multiple recursive cases.&lt;/strong&gt;&lt;br&gt;
Example the collatz conjecture. &lt;/p&gt;

&lt;p&gt;The next C and JavaScript examples define a &lt;code&gt;collatz&lt;/code&gt; function that calculates how many steps it takes to get "back to 1":&lt;/p&gt;

&lt;p&gt;&lt;em&gt;C example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;collatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// base case&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// recursive case: even numbers&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;collatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// recursive case: odd numbers&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;collatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;collatz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// base case&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// recursive case: even numbers&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;collatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// recursive case: odd numbers&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;collatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Merge Sort &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To divide an array into smaller arrays to sort and then, combine those sorted arrays back together in sorted order.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode example #1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If only one element
  Return
Else
    Sort left half of elements
    Sort right half of elements
    Merge sorted halves
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Pseudocode example #2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sort the left half of the array (assuming n &amp;gt; 1)
Sort right half of the array (assuming n &amp;gt; 1)
Merge the two halves together
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;C example (recursive):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// merges two subarrays of arr[]&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="c1"&gt;// temp arrays&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;Right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 

    &lt;span class="c1"&gt;// copy data to temp arrays&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
        &lt;span class="n"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
        &lt;span class="n"&gt;Right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 

    &lt;span class="c1"&gt;// merge the temp arrays back into arr[]&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// init index of 1st subarray &lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// init index of 2nd subarray &lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// init index of merged subarray &lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;Right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; 
        &lt;span class="p"&gt;{&lt;/span&gt; 
            &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
            &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; 
            &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
            &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 

    &lt;span class="c1"&gt;// copy the remaining elements of Left[], if any&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
        &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 

    &lt;span class="c1"&gt;// copy the remaining elements of Right[], if any&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
        &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;   
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leftIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="c1"&gt;// instead of (l+r)/2 to avoid overflow&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="c1"&gt;// sort first and second halves &lt;/span&gt;
        &lt;span class="n"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
        &lt;span class="n"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
        &lt;span class="c1"&gt;// merge them back together&lt;/span&gt;
        &lt;span class="n"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JavaScript example (recursive):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// to merge left subarray and right subarray&lt;/span&gt;
&lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;resultArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;leftIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rightIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// concat values into the resultArray in order&lt;/span&gt;
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rightIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;resultArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
            &lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;resultArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
            &lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// concat remaining element from either left OR right&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;resultArray&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;mergeSort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// if array has one element or is empty, no need to sort&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// divide the array into left and right&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// merge back together using recursion&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Merge sort algorithm's&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst case scenario:&lt;/strong&gt; &lt;br&gt;
Having to split &lt;code&gt;n&lt;/code&gt; elements up before recombining them effectively, doubling the sorted sub-arrays as they are built.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;O(n log n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best case scenario:&lt;/strong&gt;&lt;br&gt;
The array is already sorted, but still gotta be split and recombined back together to know it is sorted.&lt;br&gt;
In Big O notation, it translates to &lt;em&gt;Ω(n log n)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Resources: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html" rel="noopener noreferrer"&gt;Comparison Sorting Algorithms (visualization)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://brilliant.org/wiki/sorting-algorithms/" rel="noopener noreferrer"&gt;Sorting Algorithms on brilliant.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/sorting-algorithms/" rel="noopener noreferrer"&gt;Sorting Algorithms on geeksforgeeks.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://imgur.com/gallery/voutF" rel="noopener noreferrer"&gt;Sorting Algorithms Visualized&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>computerscience</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript FizzBuzz solution in details</title>
      <dc:creator>Emilie Gervais</dc:creator>
      <pubDate>Sat, 12 Oct 2019 11:23:27 +0000</pubDate>
      <link>https://dev.to/emilie_gl/javascript-fizzbuzz-solution-in-details-1ih5</link>
      <guid>https://dev.to/emilie_gl/javascript-fizzbuzz-solution-in-details-1ih5</guid>
      <description>&lt;p&gt;The first time I solved FizzBuzz, my code result was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 1; i &amp;lt;= 100; i++) {
    if (i % 3 == 0 &amp;amp;&amp;amp; i % 5 == 0) {
        console.log("FizzBuzz");
    } else if (i % 3 == 0) {
        console.log("Fizz");
    } else if (i % 5 == 0) {
        console.log("Buzz");
    } else {
        console.log(i);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While looking for pull requests to make for Hacktoberfest, I stumbled upon &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/s-bridges" rel="noopener noreferrer"&gt;
        s-bridges
      &lt;/a&gt; / &lt;a href="https://github.com/s-bridges/Hacktoberfest_Fizzbuzz" rel="noopener noreferrer"&gt;
        Hacktoberfest_Fizzbuzz
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Hacktoberfest FizzBuzz Challenge
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Hacktoberfest_Fizzbuzz&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://hacktoberfest.digitalocean.com/" rel="nofollow noopener noreferrer"&gt;Hacktoberfest FizzBuzz Challenge&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This challenge is meant to help developers solve the FizzBuzz challenge in their respective programming language, as well as teach new GitHub users how to make their first Pull Request in honor of Hacktoberfest's 2019 campaign.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Problem&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;Write a short program that prints each number from 1 to 100 on a new line
For each multiple of 3, print "Rat" instead of the number.
For each multiple of 5, print "Ghost" instead of the number.
For numbers which are multiples of both 3 and 5, print "Spider" instead of the number.&lt;/p&gt;
&lt;p&gt;Write a solution (or reduce an existing one) so it has as few characters as possible.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;How to Create a Pull Request in GitHub&lt;/h1&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Click on the fork in the top right corner of this repo.&lt;/li&gt;
&lt;li&gt;Clone fork to your machine. 
&lt;code&gt;git clone https://github.com/${username}/Hacktoberfest_Fizzbuzz&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a branch titled your programming language.
&lt;code&gt;git checkout -b python&lt;/code&gt;…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/s-bridges/Hacktoberfest_Fizzbuzz" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
 ~ the &lt;a href="https://github.com/s-bridges/Hacktoberfest_Fizzbuzz" rel="noopener noreferrer"&gt;Hacktoberfest_Fizzbuzz&lt;/a&gt; repo (😢 it has now been marked as 'invalid' for hacktoberfest). On the moment though, I got excited and aimed to refactor my previous solution to the smallest possible one I could find using JavaScript.

&lt;p&gt;Note: The repo author asked to print 'Spider' instead of 'FizzBuzz', 'Ghost' instead of 'Buzz' and 'Rat' instead of 'Fizz'.&lt;/p&gt;

&lt;p&gt;My result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log([...Array(100)].map((_,i)=&amp;gt;{i++;return(i%15?'':'Spider')||(i%5?'':'Ghost')||(i%3?'':'Rat')||i;}).join('\n'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SET UP&lt;/strong&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;console.log()&lt;/code&gt;: to directly &lt;em&gt;log&lt;/em&gt; the result.&lt;br&gt;
--&amp;gt; &lt;code&gt;[...Array(100)]&lt;/code&gt;: to create a temporary array of 100 to produce the much wanted indexes.&lt;br&gt;
--&amp;gt; &lt;code&gt;.map((n,i)=&amp;gt;{}&lt;/code&gt;: to return an array filled with new content after the current values have iterated through the method's callback function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CALLBACK&lt;/strong&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;i++&lt;/code&gt;: to initiate &lt;code&gt;i&lt;/code&gt; to be 1 (in this case, we don't want to start from 0).&lt;br&gt;
--&amp;gt; &lt;code&gt;return&lt;/code&gt;: to stop the function from running once its done iterating and return the new array.&lt;br&gt;
--&amp;gt; &lt;code&gt;(i%15?'':'Spider')&lt;/code&gt;: check if &lt;code&gt;i&lt;/code&gt; is divisible by 15 (if divisible by 15, it is also divisible by both 3 and 5); if there's a remainder, print nothing; if there isn't, print 'Spider'.&lt;br&gt;
--&amp;gt; &lt;code&gt;||&lt;/code&gt;: OR&lt;br&gt;
--&amp;gt; &lt;code&gt;(i%5?'':'Ghost')&lt;/code&gt;: check if &lt;code&gt;i&lt;/code&gt; is divisible by 5; if there's a remainder, print nothing; if there isn't, print 'Ghost'. &lt;br&gt;
--&amp;gt; &lt;code&gt;||&lt;/code&gt;: OR&lt;br&gt;
--&amp;gt; &lt;code&gt;(i%3?'':'Rat')&lt;/code&gt;: check if &lt;code&gt;i&lt;/code&gt; is divisible by 3; if there's a remainder, print nothing; if there isn't, print 'Rat'. &lt;br&gt;
--&amp;gt; &lt;code&gt;||&lt;/code&gt;: OR&lt;br&gt;
--&amp;gt; &lt;code&gt;i&lt;/code&gt;: if it isn't divisible by any of the previous options, print the fucking number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FINISHING&lt;/strong&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;.join('\n')&lt;/code&gt;: to return a string of all the concatenated elements of the new array using a new line as separator; thus, jumping a line between each elements to &lt;code&gt;console.log&lt;/code&gt; a nice SpiderGhostRatNumber list! =)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS. In JavaScript, an integer converts to a boolean such that 0 is false and all non-zero values (even negative ones) are true.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l1hj1c8ryxhdc4bpgax.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l1hj1c8ryxhdc4bpgax.gif" alt="Melting Statue Of Liberty GIF" width="308" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's your FizzBuzz solution?
&lt;/h2&gt;

</description>
      <category>fizzbuzz</category>
      <category>javascript</category>
      <category>hacktoberfest</category>
    </item>
  </channel>
</rss>
