<?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: StormyTalent</title>
    <description>The latest articles on DEV Community by StormyTalent (@stormytalent).</description>
    <link>https://dev.to/stormytalent</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%2F861527%2F6dcfd3eb-3117-4f94-8b6c-ea17bdb34ccd.png</url>
      <title>DEV Community: StormyTalent</title>
      <link>https://dev.to/stormytalent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stormytalent"/>
    <language>en</language>
    <item>
      <title>JavaScript Interview Coding Test Problem 8</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Mon, 18 Jul 2022 03:09:21 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-8-4c4i</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-8-4c4i</guid>
      <description>&lt;p&gt;Learn how to create a queue when the only data structure you have access to is a stack.&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Write a function that creates a queue using two stacks. Besides these twD stacks, you may not use any additional data structures in your implementation. It  should  have the  methods   enqueue ,  dequeue , and   s ize .&lt;/p&gt;

&lt;p&gt;Feel free to change the code provided below when you start. It’s meant to be a guide.&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   class Queue {
2     constructor() {
3       this._enqueueStorage[];
4       this._dequeueStorage[];
5     }
6
7     enqueue(1tem) (
8       this. enqueuestorage.push(item); 9  }
10
11    dequeue( ) (
12      if(this. dequeueStorage.length) (
13        return this. dequeueStorage.pop();
14  }
15
16  1f(th1s ._enqueue5torage . 1ength) (
17    while(this. enqueue5torage.length) {
18    this. dequeuestorage.push(this. enqueue5torage.pop()); 19
20
21      return this. dequeueStorage.pop(); 
22
23
24     console.warn('Attempting to dequeue from an empty queue');
25  return undefined; 26     

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works&lt;/strong&gt;&lt;br&gt;
We have two storage stacks, this ._enqueueStorage and&lt;br&gt;
this . dequeuestorage . To see how they interact, let’s go thrDugh an example.&lt;br&gt;
&lt;strong&gt;Enqueuing&lt;/strong&gt;&lt;br&gt;
We want to put 5 elements onto the queue: 1, 2, 3, 4, and s . We enqueue&lt;br&gt;
all of these, and they all go into enqueuestorage .&lt;/p&gt;

&lt;p&gt;enqueuestorage: [1, 2, 3, 4, 5] dequeuestorage: []&lt;/p&gt;

&lt;p&gt;We now want to dequeue an item. Let’s dive into our dequeue function.&lt;br&gt;
&lt;strong&gt;Dequeuing&lt;/strong&gt;&lt;br&gt;
We skip the if-statement on line 12 since dequeuestorage is empty. We move&lt;br&gt;
on to line 16.&lt;/p&gt;

&lt;p&gt;Inside that if-statement (line 16), we pop every item off of enqueuestorage and put them into dequeuestorage . When the while-loop (lines 17 - 19) is finished, enqueuestorage is empty and dequeuestorage  has the five items, but in reverse.&lt;br&gt;
enqueuestorage: [) dequeuestorage: [5, 4, 3, 2, 1]&lt;br&gt;
On line 21, we pop dequeuestorage and return the item, i.&lt;br&gt;
enqueuestorage: [] dequeuestorage: [5, 4, 3, 2]&lt;br&gt;
If we want to dequeue again, we can enter the dequeue method once more. This time we go into the first if-statement and pop an item off of dequeuestorage and return it.&lt;br&gt;
enqueuestorage: [] dequeuestorage: [5, 4, 3]&lt;br&gt;
We can keep dequeuing if we like. As long as dequeuestorage  has items in it, the last item will be popped off and returned to us.&lt;br&gt;
&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
These steps together make it so our queue functions properly. Enqueuing pushes items onto one stack. Dequeuing pops them from the second stack. When the second stack is empty and we want to dequeue, we empty the first stack onto the second, reversing the order of items.&lt;br&gt;
&lt;strong&gt;Enqueue Time&lt;/strong&gt;&lt;br&gt;
Every enqueue event is a simple push onto a stack. This means that each enqueue has a time complexity of:&lt;br&gt;
0(1)&lt;br&gt;
&lt;strong&gt;Dequeue Time&lt;/strong&gt;&lt;br&gt;
So, for most cases, we have o(1) , and for a few rare cases, we have o(n) We can merge these into a single time complexity.&lt;br&gt;
&lt;strong&gt;Queue Lifecycle&lt;/strong&gt;&lt;br&gt;
Let’s track the life of three items in our queue. Starting with an empty queue, let’s enqueue i , 2, and 3 . This puts them on our first stack.&lt;br&gt;
enqueuestorage: [1, 2, 3] dequeuestorage: []&lt;br&gt;
So far, we’ve performed 3 operations: inserting each of those items onto the stack.&lt;br&gt;
Let’s dequeue all three items. First, all items from enqueuestorage get&lt;br&gt;
transferred to dequeuestorage .&lt;br&gt;
enqueuestorage: [] dequeuestorage: [1, 2, 3]&lt;br&gt;
We’ll say that a transference is 1 Dperation. This is another 3 operatiDns total, bringing us up to 6.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 7</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Mon, 18 Jul 2022 02:50:30 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-7-4ipb</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-7-4ipb</guid>
      <description>&lt;p&gt;Learn how to determine if brackets are balanced or not. This is an actual problem that software developers must occasionally solve and many dev tools have their own implementation of it. We’ll learn how a code editor can pick up our mistakes and highlight exactly which brackets don't match.&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Given a string, return  true  if it contains all balanced parentheses   ( ) curly- brackets () , and square-brackets [].&lt;br&gt;
Input: String&lt;br&gt;
Output: Boolean&lt;br&gt;
&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
is8alanced("(x + y) - (4)”); // -&amp;gt; true is8alanced("(((10 ) (}) ((?)(:)))”); // -› true isBalanced("[{()}]”); // -› true is8alanced("(50)(”); // -&amp;gt; false&lt;br&gt;
isBalanced("[{]}”); // -› false&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2   const openstack = [];
3   const open = '([{';
4   const close = ')]}';
5   const matches - {
6   ')': '(',
7   ']': '[',
8   '}': '{'
9   };
10
11  for (let i - 0; i ‹ str.length; i++) (
12  const char  str[i]; 13
14  // If it's an open bracket, push it into our array
15      if(open.includes(char)) (   
16      openstack.push(char);   
17          
18      // If it's a close bracket  
19      } else if(close.includes(char)) (   
20      // pop an item from the open brackets array.    
21      const lastopenBracket   openStack.pop();    
22          
23      // If the open and close bracket don't match,   return false
24      if(matches[char] !== lastopenBracket) { 
25      return false;   
26          
27      

28      

29          
30      // Ensures there are no characters left on the stack    
31      return !openStack.length;   
32  }       

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works&lt;/strong&gt;&lt;br&gt;
In our for-loop, we process every character. If the current character is an open bracket, we push it onto our openstack array.&lt;br&gt;
If it’s not a bracket, we do nothing.&lt;br&gt;
Once we’re done processing the string, we have to check to make sure there&lt;br&gt;
are no open brackets left on our stack. If there are, our string is unbalanced.&lt;br&gt;
&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
This is a solutiDn with a time complexity Df:&lt;br&gt;
0(n).&lt;br&gt;
Every character is prDcessed in a loop. Inside the lDop, we perform only count-time actions.&lt;br&gt;
&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
The space complexity is:&lt;br&gt;
0(n).&lt;br&gt;
Characters are stored in an array, generally proportional to the size of the input.&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
There are many ways to skin this cat. Another solution wDuld have been to have two pointers, one at the beginning and one at the end, moving towards the middle. They would be checking to make sure that brackets matched until they met. This would also be an o(n) solution.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 6</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Mon, 18 Jul 2022 01:54:00 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-6-1f8m</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-6-1f8m</guid>
      <description>&lt;p&gt;Learn two different ways to complete the search of a sorted array. We'll go over the brute force method and a more elegant method.&lt;br&gt;
&lt;strong&gt;Sorted Search&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Write a function that accepts a sorted array of integers and a number. Return the index of that number if present. The function should return -1 for target values not in the array.&lt;br&gt;
&lt;strong&gt;Input: **Array of Integers, Integer&lt;br&gt;
**Output: **An integer from -1 onwards.&lt;br&gt;
**Solution 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   function search(numbers, target) {
2     for(let i = 0; i &amp;lt; numbers.length; i++) {
3       if(numbers[i] === target) {
4         return i;
5       }
6     }
7
8     return -1;
9   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solution is very simple. We go through the array and try to find our target.&lt;br&gt;
&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
Since we're going through the whole array, the time complexity is: O(n).&lt;br&gt;
&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
Since we store a set number of variables, space complexity is: 0(1).&lt;br&gt;
&lt;strong&gt;Binary Search&lt;/strong&gt;&lt;br&gt;
We can come up with a better solution. Since the array is sorted, we can essentially jump around the array until we find the index we're looking for.&lt;br&gt;
&lt;strong&gt;Finding a Word&lt;/strong&gt;&lt;br&gt;
Imagine looking for a word in a dictionary. Would it be efficient to go through every single word until we find the one we want? No, that would be horribly inefficient.&lt;br&gt;
A better approach would be to open the dictionary halfway. If our word is alphabetically before the words in the middle page, we know our word is in the first half of the book.&lt;br&gt;
We can then flip to ~1/4 of the way through the dictionary. Again, repeating the above process, we can eliminate another half of the remaining pages.&lt;br&gt;
We can repeat the above steps again and again until we find our word. This ensures that even if the dictionary is huge, we can find our word much faster than if we were to go through each word individually.&lt;br&gt;
&lt;strong&gt;Scaling&lt;/strong&gt;&lt;br&gt;
In fact, if we double the size of the dictionary by adding in more words, we would only have to repeat this process one more time. That's not much more work even though the dictionary is much thicker.&lt;br&gt;
Let's turn this approach into code.&lt;br&gt;
&lt;strong&gt;Solution 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   function binarySearch(numbers, target) {
2     let startindex = 0;
3     let endindex = numbers.length - 1;
4
5     if(target &amp;lt; numbers[startindex] || target &amp;gt; numbers[endindex]) {
6       return -1;
7     }
8
9       while(true) {
10    if(numbers[startindex] === target) {
11      return startindex:
12      }
13
14      if(numbers[endindex] === target) {
15        return endindex; }
17
18  if(endindex - startindex &amp;lt;= l) {
19  //indicates the number isn't present
20  return -1;
22
23  const middleindex = Math.floor((startindex + endindex)/2);
24
25      if(target &amp;gt; numbers[middlelndex]) {
26        Startindex = middlelndex + 1;
27      } else if(target &amp;lt; numbers[middlelndex]) {
28        endindex = middleindex - 1;
29      } else {
30        return middlelndex;
31      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works&lt;/strong&gt;&lt;br&gt;
We start by ensuring that the target is within range of the array, returning&lt;br&gt;
false  otherwise.&lt;/p&gt;

&lt;p&gt;In the loop, we first check if the target is equal to the values at the beginning and end of our array. Then we check if the target is larger or smaller than the value at the center.&lt;br&gt;
If it's smaller than the value at the center, we know that it's going to be somewhere in the 1st half of the array. We can focus on that.&lt;br&gt;
If it's larger, we know that it can't possibly be in the first half, so we can focus on searching the 2nd half.&lt;br&gt;
Over and over, we cut the amount we have to search by half until we close in on its location. If we find it along the way, we can stop and return its index.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 5</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sat, 09 Jul 2022 13:39:08 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-5-4ji3</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-5-4ji3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Creating a Queue with Limited Data Structures&lt;/strong&gt;&lt;br&gt;
Learn how to create a queue when the only data structure you have access to is a stack.&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 4</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sat, 09 Jul 2022 12:04:07 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-4-35b5</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-4-35b5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Balanced Brackets&lt;/strong&gt;&lt;br&gt;
Learn how to determine if brackets are balanced or not. This is an actual problem that software developers must occasionally solve and many dev tools have their own implementation of it. We’ll learn how a code editor can pick up our mistakes and highlight exactly which brackets don't match.&lt;br&gt;
&lt;strong&gt;Balanced Brackets&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Given a string, return  true  if it contains all balanced parentheses() curly-brackets(), and square-brackets []&lt;br&gt;
Input: String&lt;br&gt;
Output: Boolean&lt;br&gt;
&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
is8alanced("(x + y) - (4)”); // -&amp;gt; true is8alanced("(((10 ) (}) ((?)(:)))”); // -› true isBalanced("[{()}]”); // -› true is8alanced("(50)(”); // -&amp;gt; false&lt;br&gt;
isBalanced("[{]}”); // -› false&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   funct1on 1sBa1anced(str) {
2   //  Your code here
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2   const openstack = [];
3   const open = '([{';
4   const close = ')]}';
5   const matches - {
6   ')': '(',
7   ']': '[',
8   '}': '{'
9   };
10
11  for (let i - 0; i ‹ str.length; i++) (
12  const char str[i]; 13
14  // If it's an open bracket, push it into our array
15  if(open.includes(char)) (   
16    openstack.push(char); 
17          
18    // If it's a close bracket    
19    } else if(close.includes(char)) ( 
20      // pop an item from the open brackets array.    
21      const lastopenBracket   openStack.pop();    
22          
23      // If the open and close bracket don't match,    
            return false
24      if(matches[char] !== lastopenBracket) { 
25        return false; 
26      }   
27      
28
30  // Ensures there are no characters left on the stack    
31  return !openStack.length;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works&lt;/strong&gt;&lt;br&gt;
In our for-loop, we process every character. If the current character is an open bracket, we push it onto our openstack array.&lt;br&gt;
If it’s not a bracket, we do nothing.&lt;br&gt;
Once we’re done processing the string, we have to check to make sure there&lt;br&gt;
are no open brackets left on our stack. If there are, our string is unbalanced.&lt;br&gt;
&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
This is a solutiDn with a time complexity Df:&lt;br&gt;
0(n)&lt;br&gt;
&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
The space complexity is:&lt;br&gt;
0(n)&lt;br&gt;
Characters are stored in an array, generally proportional to the size of the input.&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
There are many ways to skin this cat. Another solution wDuld have been to have two pointers, one at the beginning and one at the end, moving towards the middle. They would be checking to make sure that brackets matched until they met. This would also be an o(n) solution.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 3</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sat, 09 Jul 2022 10:57:55 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-3-348g</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-3-348g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Sorted Search&lt;/strong&gt;&lt;br&gt;
Learn two different ways to complete the search of a sorted array. We'll go over the brute force method and a more elegant method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sorted Search&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Write a function that accepts a sorted array of integers and a numher. Return the index of that number if present. The functiDn should return -i for target values not in the array.&lt;br&gt;
Input: Array of Integers, Integer&lt;/p&gt;

&lt;p&gt;Output: An integer from -i onwards.&lt;br&gt;
&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
search([1, 3, 6, 13, 17], 13); // -&amp;gt; 3&lt;br&gt;
search([l, 3, 6, 13, 17], 12); // -&amp;gt; -1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   function search(numbers, target) {
2   // Your code here 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1   function search(numbers, target) {
2   for(let i = 0; i &amp;lt; numbers.length; i++) {
3       if(numbers[i] === target) {
4         return i; 
5       }
6   }   
7           
8   return -1; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solution is very simple. We go through the array and try to find Dur target.&lt;br&gt;
&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
Since we’re going through the whole array, the time complexity is:&lt;br&gt;
O(n)&lt;br&gt;
&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
Since we store a set number of variables, space complexity is:&lt;br&gt;
O(1)&lt;br&gt;
&lt;strong&gt;Binary Search&lt;/strong&gt;&lt;br&gt;
We can cDme up with a better solution. Since the array is sDrted, we can essentially jump around the array until we find the index we’re looking for.&lt;br&gt;
&lt;strong&gt;Finding a Word&lt;/strong&gt;&lt;br&gt;
Imagine looking for a word in a dictionary. Would it be efficient to go  through every single word until we find the one we want? No, that would be horribly inefficient.&lt;br&gt;
A better approach would be to Dpen the dictiDnary halfway. If our word is alphabetically before the words in the middle page, we know our word is in the first half of the hoDk.&lt;br&gt;
We can then flip to -1/4 of the way through the dictionary. Again, repeating the above process, we can eliminate another half of the remaining pages.&lt;br&gt;
We can repeat the above steps again and again until we find our word. This ensures  that even if the dictionary is huge, we can find  Dur word much faster than if we were to go through each word individually.&lt;br&gt;
&lt;strong&gt;Scaling&lt;/strong&gt;&lt;br&gt;
In fact, if we double the size of the dictionary by adding in more words, we would only have to repeat this process one more time. That’s not much more work even thDugh the dictionary is much thicker.&lt;br&gt;
Let’s turn this approach into code.&lt;br&gt;
&lt;strong&gt;Solution 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function binarySearch(numbers, target) (
let startIndex = 0;
let endIndex = numbers.length - 1;
if(target ‹ numbers[startlndex] || target &amp;gt; numbers[endIndex]){
  return--1;
}
while(true) {
  if(numbers[startlndex] === target) {
    return tartIndex;
  }
14  if(numbers[endIndex].===-target).{
15  return.endlndex;
16  ........}
17
18  .- ......if(endIndex. -.startIndex. ‹=-1).{
19  //-indicates-the-number-isn't-present
20  return.-1;
21  ........}
22
23   
      const middleIndex = Math.floor((startIndex + endIndex) / 2);
24
25  if(target › numbers[middleIndex]) (
26   startIndex = middleIndex + 1;
27  } else if(target ‹ numbers[middlelndex]) { 
          endIndex = middleIndex - 1;
    } else {
    return middleIndex;
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works&lt;/strong&gt;&lt;br&gt;
We start by ensuring that the target is within range of the array, returning&lt;br&gt;
false Otherwise.&lt;/p&gt;

&lt;p&gt;In the loop, we first check if the target is equal to the values at the beginning and end of Dur array. Then we check if the target is larger  Dr smaller than  the value at the center.&lt;br&gt;
If it’s smaller than the value at the center, we know that it’s going to be somewhere in the 1st half of the array. We can focus on that.&lt;br&gt;
If it’s larger, we know that it can’t possibly be in the first half, so we can focus on searching the 2nd half.&lt;br&gt;
Over and over, we cut the amount we have to search by half until we close in on its locatiDn. If we find it alDng the way, we can stDp and return its index.&lt;br&gt;
&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
We’re eliminating half of the array in every iteration of our loop, so time&lt;br&gt;
complexity is O(log2(n)), which simplifies to:&lt;br&gt;
O(log(n))&lt;br&gt;
&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
The space complexity is again:&lt;br&gt;
O(1)&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Dealing with sDrted data allows us to make many optimizations. We knDw the relationship of an item to the items before it and after it, allowing us to jump around the data and hone in on the value we’re looking for.&lt;br&gt;
If data comes in  unsorted, sometimes it would  be wise to sort it  ourselves.  If we have a sDlution with o(n^2) time cDmplexity, it’s worth it to see if we can sortthedaTa.&lt;br&gt;
Sorting it would be an o(n  *  log(n) )  process,  which  is  better than  o(n•2)  . Once it’s sorted, the next steps are often linear  or logarithmic,  meaning  they are insignificant compared to the sorting itself.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 2</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sat, 02 Jul 2022 14:30:56 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-2-3obm</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-2-3obm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Maximum Profits&lt;/strong&gt;&lt;br&gt;
We'll discuss how to write a function that can reap the maximum profits from a day's stock data. We'll discuss both the simple brute-force solution and an elegant solution to this problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Suppose we could access yesterday’s prices for a certain stock as a chronological list. Write a function that takes the list and returns the highest profit possible from one purchase and one sale of the stock yesterday.&lt;br&gt;
For example, a stock price list of [18, 7, 5, 8, 11, 9] Shows that the stock started at i8 and ended at , going through the numbers chronologically. There is at least a 1-minute difference between the stock prices.&lt;br&gt;
Taking that array as input, our function should return 6, the maximum possible profit from buying when the price was s and selling when the price was ii.&lt;br&gt;
If no profit can be made, return 8.&lt;/p&gt;

&lt;p&gt;No “shorting” — you must buy befDre you sell. You may not buy and sell in the same time step.&lt;br&gt;
Input: Array of Numbers&lt;br&gt;
Output: Number&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints&lt;/strong&gt;&lt;br&gt;
  • We’ll have to convert this array of stock prices into possible profits&lt;br&gt;
  • Think about the fact that this is a chronologically ordered list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getMaxProfit(prices) {
    // Your code here 3
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
let count = 0; 2&lt;br&gt;
function getMaxProfit(prices) {&lt;br&gt;
  const possibleProfits = [];&lt;/p&gt;

&lt;p&gt;for(let i = 0; i &amp;lt; prices.length; i++) (&lt;br&gt;
    for(let j = i; j &amp;lt; prices.length; j++) {&lt;br&gt;
      possibleProfits.push(prices[j] - prices[i]);&lt;br&gt;
      count++;&lt;br&gt;
      return Math.max(...possibleProfits);&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;getMaxProfit([1, 2, 3]);&lt;br&gt;
  console.log(count);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Loop&lt;/strong&gt;&lt;br&gt;
The second line in the loop updates our minimum price if necessary.&lt;br&gt;
The third line updates the maximum profit if the profit from buying at our current minimum price and selling at the current number is greater than the current max profit.&lt;br&gt;
At the end, we return that maximum profit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time&lt;/strong&gt;&lt;br&gt;
This time, we go through the array only once, giving us an efficiency of:&lt;br&gt;
&lt;strong&gt;0(n)&lt;/strong&gt;&lt;br&gt;
Much better than o(n^2) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space&lt;/strong&gt;&lt;br&gt;
We don’t create any arrays or store values across lDop iteratiDns. All we track is the two variables declared at the beginning. We maintain the same amount of information regardless of array size, so we have a space complexity of&lt;br&gt;
&lt;strong&gt;0(1)&lt;/strong&gt;&lt;br&gt;
It’s the best we can get.&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This is the solution that would win the interviewer over. It’s difficult and it shows the ability to logically deal with hoth numbers and time. It’s elegant, short and sweet. It has the best time and space complexities imaginable for this type of problem.&lt;br&gt;
Take away the idea that there are times when you can turn an o(n^2) solution into an O(n) solution with some critical thinking. Occasionally, keeping track of important values and updating them in the loop will vastly speed up a function.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Interview Coding Test Problem 1</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sat, 02 Jul 2022 09:32:22 +0000</pubDate>
      <link>https://dev.to/stormytalent/javascript-interview-coding-test-problem-1-3oah</link>
      <guid>https://dev.to/stormytalent/javascript-interview-coding-test-problem-1-3oah</guid>
      <description>&lt;p&gt;&lt;strong&gt;Instructions&lt;/strong&gt;&lt;br&gt;
Write a function that accepts two parameters, both arrays. The arrays can have both strings and numbers. Return true if the second array is a subset of the first.&lt;br&gt;
In other words, determine if every item in the 2nd array is also present somewhere in the 1st array.&lt;br&gt;
Input: Array of Numbers &amp;amp; Strings, Array of Numbers &amp;amp; Strings&lt;br&gt;
Output: Boolean&lt;br&gt;
&lt;strong&gt;Examples#&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arraySubset([2, 1, 3], [1, 2, 3]); // -&amp;gt; true
arraySubset([2, 1, 1, 3], [1, 2, 3]); // -&amp;gt; true
arraySubset([1, 2], [1, 2, 3]); // -&amp;gt; false
arraySubset([1, 2, 3], [1, 2, 2, 3]); // -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hints#&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This problem has multiple solutions with different time complexities.&lt;/li&gt;
&lt;li&gt;We'll need to consider how to deal with repeats, such as wehn an item is present twice.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function arraySubset(arr, sub) {
  // Your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution 1#&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function arraySubset(arr, sub) {
  if (sub.length &amp;gt; arr.length) {
    return false;
  }
  for(let i = 0; i &amp;lt; sub.length; i++) {
    const arrIndex = arr.indexOf(sub[i]);
    if (arrIndex === -1) {
      return false;
    }
    delete arr[arrIndex];
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works#&lt;/strong&gt;&lt;br&gt;
This function starts with a simple check. The subset can't be larger than the superset, by definition.&lt;br&gt;
We continue by looping through every item in the second array. Our function then finds the index of this item in the first array. If that index is -1, indicating that it is not present, we can return false immediately.&lt;br&gt;
Otherwise, we delete it from the first array, This ensures that if it is encountered again in the second array, it can't use the same value in the first array.&lt;br&gt;
Once we get through the entire second array we can return true.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time#&lt;/strong&gt;&lt;br&gt;
We have two inputs, so we'll refer to their lengths as m and n.&lt;br&gt;
We loop over n, indicating O(n) already. Inside the loop, there is a call to indexOf(). This itself is a loop, as the engine has to go through the array to find the index.&lt;br&gt;
So we're at: &lt;strong&gt;O(m * n),#&lt;/strong&gt;&lt;br&gt;
which is our final time complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space#&lt;/strong&gt;&lt;br&gt;
We use the same amount of space no matter how large the inputs, so it's: &lt;strong&gt;O(1).#&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Caveats#&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our function is not a pure function. We delete items out of the first array. To get around this, we could first make a copy of the first array and work with that instead. It would not change time complexity but would increase space complexity to O(m).Solution 2 works around this problem.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function arraySubset(arr, sub) {
  if(sub.length &amp;gt; arr.length) {
    return false;
  }

  const arrCount = {};

  for(let i = 0; i &amp;lt; arr.length; i++) {
    const item= arr[i];
    if(arrCount[item] !== undefined) {
      arrCount[item]++;
    } else {
      arrCount[item] = 1;
    }
  }

  for(let i = 0; i &amp;lt; sub.length; i++) {
    canst currentitem = sub[i];
    if(arrCount[currentitem] === undefined) {
      return false;
    }

    arrCount[currentitem]--;
    if(arrCount[currentitem] === 0) {
      delete arrCount[currentitem];
    }
  }

  return true;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it Works# **&lt;br&gt;
**Time#&lt;/strong&gt;&lt;br&gt;
Every object manipulation performed here has O(l) efficiency so they won't factor into our calculations.&lt;br&gt;
Looping over the second array gives us O(n). Since it's not inside the first loop, we add the two variables, giving us:&lt;br&gt;
&lt;strong&gt;O(m + n).#&lt;/strong&gt;&lt;br&gt;
This is much better than o(m * n).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space#&lt;/strong&gt;&lt;br&gt;
In this solution, we end up malting a copy of the items inm , so our space complexity is O(m).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extending the Problem#&lt;/strong&gt;&lt;br&gt;
Our solution works for arrays that contain only numbers and strings. What if we wanted to make this function work for arrays that contain any type of data?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objects#&lt;/strong&gt;&lt;br&gt;
Using an object wouldn't work. Object keys can only be strings. Any key we insert into the object would automatically be coerced to a string.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>50+ hints JS(ES6+) developer must know (10th part)</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Sun, 12 Jun 2022 01:46:28 +0000</pubDate>
      <link>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-10th-part-43ef</link>
      <guid>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-10th-part-43ef</guid>
      <description>&lt;p&gt;My thanks to everybody who follows to this tenth, the last blog of JS hint.&lt;br&gt;
Today we are going to see some useful cases of Accessors, Events, and JQuery.&lt;br&gt;
&lt;strong&gt;1. Accessors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello').&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
class Dragon {
  get age() {
    // ...
  }

  set age(value) {
    // ...
  }
}

// good
class Dragon {
  getAge() {
    // ...
  }

  setAge(value) {
    // ...
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the property/method is a boolean, use isVal() or hasVal().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
if (!dragon.age()) {
  return false;
}

// good
if (!dragon.hasAge()) {
  return false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s okay to create get() and set() functions, but be consistent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Jedi {
  constructor(options = {}) {
    const lightsaber = options.lightsaber || 'blue';
    this.set('lightsaber', lightsaber);
  }

  set(key, val) {
    this[key] = val;
  }

  get(key) {
    return this[key];
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Events&lt;/strong&gt;&lt;br&gt;
When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass an object literal (also known as a "hash") instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
$(this).trigger('listingUpdated', listing.id);

// ...

$(this).on('listingUpdated', (e, listingID) =&amp;gt; {
  // do something with listingID
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// good
$(this).trigger('listingUpdated', { listingID: listing.id });

// ...

$(this).on('listingUpdated', (e, data) =&amp;gt; {
  // do something with data.listingID
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. jQuery&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const sidebar = $('.sidebar');

// good
const $sidebar = $('.sidebar');

// good
const $sidebarBtn = $('.sidebar-btn');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function setSidebar() {
  $('.sidebar').hide();

  // ...

  $('.sidebar').css({
    'background-color': 'pink',
  });
}

// good
function setSidebar() {
  const $sidebar = $('.sidebar');
  $sidebar.hide();

  // ...

  $sidebar.css({
    'background-color': 'pink',
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For DOM queries use Cascading $('.sidebar ul') or parent &amp;gt; child $('.sidebar &amp;gt; ul'). jsPerf&lt;/p&gt;

&lt;p&gt;Use find with scoped jQuery object queries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
$('ul', '.sidebar').hide();

// bad
$('.sidebar').find('ul').hide();

// good
$('.sidebar ul').hide();

// good
$('.sidebar &amp;gt; ul').hide();

// good
$sidebar.find('ul').hide();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for your time.&lt;br&gt;
Best regards.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>50+ hints JS(ES6+) developer must know (9th part)</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Wed, 08 Jun 2022 13:49:05 +0000</pubDate>
      <link>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-9th-part-10fe</link>
      <guid>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-9th-part-10fe</guid>
      <description>&lt;p&gt;Hi, everybody. Here is StormyTalent again!&lt;br&gt;
And today we are going to see some more hints what JS developer must know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Naming Conventions&lt;/strong&gt;&lt;br&gt;
Avoid single letter names. Be descriptive with your naming.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function q() {
  // ...
}

// good
function query() {
  // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use camelCase when naming objects, functions, and instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const OBJEcttsssss = {};
const this_is_my_object = {};
function c() {}

// good
const thisIsMyObject = {};
function thisIsMyFunction() {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use PascalCase only when naming constructors or classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function user(options) {
  this.name = options.name;
}

const bad = new user({
  name: 'nope',
});

// good
class User {
  constructor(options) {
    this.name = options.name;
  }
}

const good = new User({
  name: 'yup',
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not use trailing or leading underscores.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
this.__firstName__ = 'Panda';
this.firstName_ = 'Panda';
this._firstName = 'Panda';

// good
this.firstName = 'Panda';

// good, in environments where WeakMaps are available
// see https://kangax.github.io/compat-table/es6/#test-WeakMap
const firstNames = new WeakMap();
firstNames.set(this, 'Panda');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don’t save references to this. Use arrow functions or Function#bind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function foo() {
  const self = this;
  return function () {
    console.log(self);
  };
}

// bad
function foo() {
  const that = this;
  return function () {
    console.log(that);
  };
}

// good
function foo() {
  return () =&amp;gt; {
    console.log(this);
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A base filename should exactly match the name of its default export.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file 1 contents
class CheckBox {
  // ...
}
export default CheckBox;

// file 2 contents
export default function fortyTwo() { return 42; }

// file 3 contents
export default function insideDirectory() {}

// in some other file
// bad
import CheckBox from './checkBox'; // PascalCase import/export, camelCase filename
import FortyTwo from './FortyTwo'; // PascalCase import/filename, camelCase export
import InsideDirectory from './InsideDirectory'; // PascalCase import/filename, camelCase export

// bad
import CheckBox from './check_box'; // PascalCase import/export, snake_case filename
import forty_two from './forty_two'; // snake_case import/filename, camelCase export
import inside_directory from './inside_directory'; // snake_case import, camelCase export
import index from './inside_directory/index'; // requiring the index file explicitly
import insideDirectory from './insideDirectory/index'; // requiring the index file explicitly

// good
import CheckBox from './CheckBox'; // PascalCase export/import/filename
import fortyTwo from './fortyTwo'; // camelCase export/import/filename
import insideDirectory from './insideDirectory'; // camelCase export/import/directory name/implicit "index"
// ^ supports both insideDirectory.js and insideDirectory/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use camelCase when you export-default a function. Your filename should be identical to your function’s name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function makeStyleGuide() {
  // ...
}

export default makeStyleGuide;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use PascalCase when you export a constructor / class / singleton / function library / bare object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const AirbnbStyleGuide = {
  es6: {
  },
};

export default AirbnbStyleGuide;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Acronyms and initialisms should always be all uppercased, or all lowercased.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
import SmsContainer from './containers/SmsContainer';

// bad
const HttpRequests = [
  // ...
];

// good
import SMSContainer from './containers/SMSContainer';

// good
const HTTPRequests = [
  // ...
];

// also good
const httpRequests = [
  // ...
];

// best
import TextMessageContainer from './containers/TextMessageContainer';

// best
const requests = [
  // ...
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may optionally uppercase a constant only if it (1) is exported, (2) is a const (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';

// bad
export const THING_TO_BE_CHANGED = 'should obviously not be uppercased';

// bad
export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables';

// ---

// allowed but does not supply semantic value
export const apiKey = 'SOMEKEY';

// better in most cases
export const API_KEY = 'SOMEKEY';

// ---

// bad - unnecessarily uppercases key while adding no semantic value
export const MAPPING = {
  KEY: 'value'
};

// good
export const MAPPING = {
  key: 'value'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would be happy if you read this material and gain a little bit inspirations.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>50+ hints JS(ES6+) developer must know (8th part)</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Wed, 08 Jun 2022 13:42:16 +0000</pubDate>
      <link>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-8th-part-6nb</link>
      <guid>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-8th-part-6nb</guid>
      <description>&lt;p&gt;Almost end of this tips for JS developer must know.&lt;br&gt;
Today is 8th part and I will explain about Commas, Semicolons, Type Casting &amp;amp; Coercion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Commas&lt;/strong&gt;&lt;br&gt;
Leading commas: Nope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const story = [
    once
  , upon
  , aTime
];

// good
const story = [
  once,
  upon,
  aTime,
];

// bad
const hero = {
    firstName: 'Ada'
  , lastName: 'Lovelace'
  , birthYear: 1815
  , superPower: 'computers'
};

// good
const hero = {
  firstName: 'Ada',
  lastName: 'Lovelace',
  birthYear: 1815,
  superPower: 'computers',
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additional trailing comma: Yup&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad - git diff without trailing comma
const hero = {
     firstName: 'Florence',
-    lastName: 'Nightingale'
+    lastName: 'Nightingale',
+    inventorOf: ['coxcomb chart', 'modern nursing']
};

// good - git diff with trailing comma
const hero = {
     firstName: 'Florence',
     lastName: 'Nightingale',
+    inventorOf: ['coxcomb chart', 'modern nursing'],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const hero = {
  firstName: 'Dana',
  lastName: 'Scully'
};

const heroes = [
  'Batman',
  'Superman'
];

// good
const hero = {
  firstName: 'Dana',
  lastName: 'Scully',
};

const heroes = [
  'Batman',
  'Superman',
];

// bad
function createHero(
  firstName,
  lastName,
  inventorOf
) {
  // does nothing
}

// good
function createHero(
  firstName,
  lastName,
  inventorOf,
) {
  // does nothing
}

// good (note that a comma must not appear after a "rest" element)
function createHero(
  firstName,
  lastName,
  inventorOf,
  ...heroArgs
) {
  // does nothing
}

// bad
createHero(
  firstName,
  lastName,
  inventorOf
);

// good
createHero(
  firstName,
  lastName,
  inventorOf,
);

// good (note that a comma must not appear after a "rest" element)
createHero(
  firstName,
  lastName,
  inventorOf,
  ...heroArgs
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Semicolons&lt;/strong&gt;&lt;br&gt;
Yup. eslint: semi&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad - raises exception
const luke = {}
const leia = {}
[luke, leia].forEach((jedi) =&amp;gt; jedi.father = 'vader')

// bad - raises exception
const reaction = "No! That’s impossible!"
(async function meanwhileOnTheFalcon() {
  // handle `leia`, `lando`, `chewie`, `r2`, `c3p0`
  // ...
}())

// bad - returns `undefined` instead of the value on the next line - always happens when `return` is on a line by itself because of ASI!
function foo() {
  return
    'search your feelings, you know it to be foo'
}

// good
const luke = {};
const leia = {};
[luke, leia].forEach((jedi) =&amp;gt; {
  jedi.father = 'vader';
});

// good
const reaction = "No! That’s impossible!";
(async function meanwhileOnTheFalcon() {
  // handle `leia`, `lando`, `chewie`, `r2`, `c3p0`
  // ...
}());

// good
function foo() {
  return 'search your feelings, you know it to be foo';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Type Casting &amp;amp; Coercion&lt;/strong&gt;&lt;br&gt;
Perform type coercion at the beginning of the statement.&lt;/p&gt;

&lt;p&gt;Strings: eslint: no-new-wrappers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// =&amp;gt; this.reviewScore = 9;

// bad
const totalScore = new String(this.reviewScore); // typeof totalScore is "object" not "string"

// bad
const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf()

// bad
const totalScore = this.reviewScore.toString(); // isn’t guaranteed to return a string

// good
const totalScore = String(this.reviewScore);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Numbers: Use Number for type casting and parseInt always with a radix for parsing strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const inputValue = '4';

// bad
const val = new Number(inputValue);

// bad
const val = +inputValue;

// bad
const val = inputValue &amp;gt;&amp;gt; 0;

// bad
const val = parseInt(inputValue);

// good
const val = Number(inputValue);

// good
const val = parseInt(inputValue, 10);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If for whatever reason you are doing something wild and parseInt is your bottleneck and need to use Bitshift for performance reasons, leave a comment explaining why and what you’re doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// good
/**
 * parseInt was the reason my code was slow.
 * Bitshifting the String to coerce it to a
 * Number made it a lot faster.
 */
const val = inputValue &amp;gt;&amp;gt; 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Be careful when using bitshift operations. Numbers are represented as 64-bit values, but bitshift operations always return a 32-bit integer (source). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. Discussion. Largest signed 32-bit Int is 2,147,483,647:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2147483647 &amp;gt;&amp;gt; 0; // =&amp;gt; 2147483647
2147483648 &amp;gt;&amp;gt; 0; // =&amp;gt; -2147483648
2147483649 &amp;gt;&amp;gt; 0; // =&amp;gt; -2147483647
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Booleans&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const age = 0;

// bad
const hasAge = new Boolean(age);

// good
const hasAge = Boolean(age);

// best
const hasAge = !!age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for your time.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>50+ hints JS(ES6+) developer must know (7th part)</title>
      <dc:creator>StormyTalent</dc:creator>
      <pubDate>Wed, 08 Jun 2022 13:34:48 +0000</pubDate>
      <link>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-7th-part-5bfj</link>
      <guid>https://dev.to/stormytalent/50-hints-jses6-developer-must-know-7th-part-5bfj</guid>
      <description>&lt;p&gt;Hi, StormyTalent again. And today we are going through best usages of "Control statements, comments, whitespace" &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Control statements&lt;/strong&gt;&lt;br&gt;
In case your control statement (if, while etc.) gets too long or exceeds the maximum line length, each (grouped) condition could be put into a new line. The logical operator should begin the line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
if ((foo === 123 || bar === 'abc') &amp;amp;&amp;amp; doesItLookGoodWhenItBecomesThatLong() &amp;amp;&amp;amp; isThisReallyHappening()) {
  thing1();
}

// bad
if (foo === 123 &amp;amp;&amp;amp;
  bar === 'abc') {
  thing1();
}

// bad
if (foo === 123
  &amp;amp;&amp;amp; bar === 'abc') {
  thing1();
}

// bad
if (
  foo === 123 &amp;amp;&amp;amp;
  bar === 'abc'
) {
  thing1();
}

// good
if (
  foo === 123
  &amp;amp;&amp;amp; bar === 'abc'
) {
  thing1();
}

// good
if (
  (foo === 123 || bar === 'abc')
  &amp;amp;&amp;amp; doesItLookGoodWhenItBecomesThatLong()
  &amp;amp;&amp;amp; isThisReallyHappening()
) {
  thing1();
}

// good
if (foo === 123 &amp;amp;&amp;amp; bar === 'abc') {
  thing1();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't use selection operators in place of control statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
!isRunning &amp;amp;&amp;amp; startRunning();

// good
if (!isRunning) {
  startRunning();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Comments&lt;/strong&gt;&lt;br&gt;
Use /** ... */ for multiline comments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
// make() returns a new element
// based on the passed in tag name
//
// @param {String} tag
// @return {Element} element
function make(tag) {

  // ...

  return element;
}

// good
/**
 * make() returns a new element
 * based on the passed-in tag name
 */
function make(tag) {

  // ...

  return element;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use // for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it’s on the first line of a block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const active = true;  // is current tab

// good
// is current tab
const active = true;

// bad
function getType() {
  console.log('fetching type...');
  // set the default type to 'no type'
  const type = this.type || 'no type';

  return type;
}

// good
function getType() {
  console.log('fetching type...');

  // set the default type to 'no type'
  const type = this.type || 'no type';

  return type;
}

// also good
function getType() {
  // set the default type to 'no type'
  const type = this.type || 'no type';

  return type;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start all comments with a space to make it easier to read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
//is current tab
const active = true;

// good
// is current tab
const active = true;

// bad
/**
 *make() returns a new element
 *based on the passed-in tag name
 */
function make(tag) {

  // ...

  return element;
}

// good
/**
 * make() returns a new element
 * based on the passed-in tag name
 */
function make(tag) {

  // ...

  return element;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use // FIXME: to annotate problems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Calculator extends Abacus {
  constructor() {
    super();

    // FIXME: shouldn’t use a global here
    total = 0;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use // TODO: to annotate solutions to problems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Calculator extends Abacus {
  constructor() {
    super();

    // TODO: total should be configurable by an options param
    this.total = 0;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Whitespace&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use soft tabs (space character) set to 2 spaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function foo() {
∙∙∙∙let name;
}

// bad
function bar() {
∙let name;
}

// good
function baz() {
∙∙let name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Place 1 space before the leading brace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function test(){
  console.log('test');
}

// good
function test() {
  console.log('test');
}

// bad
dog.set('attr',{
  age: '1 year',
  breed: 'Bernese Mountain Dog',
});

// good
dog.set('attr', {
  age: '1 year',
  breed: 'Bernese Mountain Dog',
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Place 1 space before the opening parenthesis in control statements (if, while etc.). Place no space between the argument list and the function name in function calls and declarations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
if(isJedi) {
  fight ();
}

// good
if (isJedi) {
  fight();
}

// bad
function fight () {
  console.log ('Swooosh!');
}

// good
function fight() {
  console.log('Swooosh!');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set off operators with spaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const x=y+5;

// good
const x = y + 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;End files with a single newline character.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
import { es6 } from './AirbnbStyleGuide';
  // ...
export default es6;
// bad
import { es6 } from './AirbnbStyleGuide';
  // ...
export default es6;↵

// good
import { es6 } from './AirbnbStyleGuide';
  // ...
export default es6;↵
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which emphasizes that the line is a method call, not a new statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
$('#items').find('.selected').highlight().end().find('.open').updateCount();

// bad
$('#items').
  find('.selected').
    highlight().
    end().
  find('.open').
    updateCount();

// good
$('#items')
  .find('.selected')
    .highlight()
    .end()
  .find('.open')
    .updateCount();

// bad
const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true)
    .attr('width', (radius + margin) * 2).append('svg:g')
    .attr('transform', `translate(${radius + margin},${radius + margin})`)
    .call(tron.led);

// good
const leds = stage.selectAll('.led')
    .data(data)
  .enter().append('svg:svg')
    .classed('led', true)
    .attr('width', (radius + margin) * 2)
  .append('svg:g')
    .attr('transform', `translate(${radius + margin},${radius + margin})`)
    .call(tron.led);

// good
const leds = stage.selectAll('.led').data(data);
const svg = leds.enter().append('svg:svg');
svg.classed('led', true).attr('width', (radius + margin) * 2);
const g = svg.append('svg:g');
g.attr('transform', `translate(${radius + margin},${radius + margin})`).call(tron.led);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Leave a blank line after blocks and before the next statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
if (foo) {
  return bar;
}
return baz;

// good
if (foo) {
  return bar;
}

return baz;

// bad
const obj = {
  foo() {
  },
  bar() {
  },
};
return obj;

// good
const obj = {
  foo() {
  },

  bar() {
  },
};

return obj;

// bad
const arr = [
  function foo() {
  },
  function bar() {
  },
];
return arr;

// good
const arr = [
  function foo() {
  },

  function bar() {
  },
];

return arr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not pad your blocks with blank lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function bar() {

  console.log(foo);

}

// bad
if (baz) {

  console.log(qux);
} else {
  console.log(foo);

}

// bad
class Foo {

  constructor(bar) {
    this.bar = bar;
  }
}

// good
function bar() {
  console.log(foo);
}

// good
if (baz) {
  console.log(qux);
} else {
  console.log(foo);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not use multiple blank lines to pad your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
class Person {
  constructor(fullName, email, birthday) {
    this.fullName = fullName;


    this.email = email;


    this.setAge(birthday);
  }


  setAge(birthday) {
    const today = new Date();


    const age = this.getAge(today, birthday);


    this.age = age;
  }


  getAge(today, birthday) {
    // ..
  }
}

// good
class Person {
  constructor(fullName, email, birthday) {
    this.fullName = fullName;
    this.email = email;
    this.setAge(birthday);
  }

  setAge(birthday) {
    const today = new Date();
    const age = getAge(today, birthday);
    this.age = age;
  }

  getAge(today, birthday) {
    // ..
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not add spaces inside parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
function bar( foo ) {
  return foo;
}

// good
function bar(foo) {
  return foo;
}

// bad
if ( foo ) {
  console.log(foo);
}

// good
if (foo) {
  console.log(foo);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not add spaces inside brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const foo = [ 1, 2, 3 ];
console.log(foo[ 0 ]);

// good
const foo = [1, 2, 3];
console.log(foo[0]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add spaces inside curly braces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const foo = {clark: 'kent'};

// good
const foo = { clark: 'kent' };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per above, long strings are exempt from this rule, and should not be broken up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
const foo = jsonData &amp;amp;&amp;amp; jsonData.foo &amp;amp;&amp;amp; jsonData.foo.bar &amp;amp;&amp;amp; jsonData.foo.bar.baz &amp;amp;&amp;amp; jsonData.foo.bar.baz.quux &amp;amp;&amp;amp; jsonData.foo.bar.baz.quux.xyzzy;

// bad
$.ajax({ method: 'POST', url: 'https://airbnb.com/', data: { name: 'John' } }).done(() =&amp;gt; console.log('Congratulations!')).fail(() =&amp;gt; console.log('You have failed this city.'));

// good
const foo = jsonData
  &amp;amp;&amp;amp; jsonData.foo
  &amp;amp;&amp;amp; jsonData.foo.bar
  &amp;amp;&amp;amp; jsonData.foo.bar.baz
  &amp;amp;&amp;amp; jsonData.foo.bar.baz.quux
  &amp;amp;&amp;amp; jsonData.foo.bar.baz.quux.xyzzy;

// good
$.ajax({
  method: 'POST',
  url: 'https://airbnb.com/',
  data: { name: 'John' },
})
  .done(() =&amp;gt; console.log('Congratulations!'))
  .fail(() =&amp;gt; console.log('You have failed this city.'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bad
var foo = 1,bar = 2;
var arr = [1 , 2];

// good
var foo = 1, bar = 2;
var arr = [1, 2];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
