<?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: SCDan0624</title>
    <description>The latest articles on DEV Community by SCDan0624 (@scdan0624).</description>
    <link>https://dev.to/scdan0624</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%2F334158%2Ff98b308b-320c-405a-82e8-b9522c0208f6.jpg</url>
      <title>DEV Community: SCDan0624</title>
      <link>https://dev.to/scdan0624</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scdan0624"/>
    <language>en</language>
    <item>
      <title>Functions in Python for Beginners</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Sat, 13 Feb 2021 20:22:37 +0000</pubDate>
      <link>https://dev.to/scdan0624/functions-in-python-for-beginners-259g</link>
      <guid>https://dev.to/scdan0624/functions-in-python-for-beginners-259g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;br&gt;
Similar to other coding languages, functions in python are a blocks of code that will run only after being called. Today we will look at how to create a function and how to use arguments in functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
To call a function you use the &lt;code&gt;def&lt;/code&gt; keyword followed by the function name, a parenthesis, and a colon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction():
    print("Hello")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When creating a function in python you must have your block of code after the function name indented:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# correct
def myFunction():
    print("Hello")

# incorrect
def myFunction():
print("Hello")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Calling a function&lt;/strong&gt;&lt;br&gt;
To call your function you use the function name, followed by a parenthesis:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction():
    print("Hello")

myFunction() # prints Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Arguments&lt;/strong&gt;&lt;br&gt;
Arguments are used to pass information into the function. Arguments are written inside the parentheses of your function. You can name the arguments what you like (similar to a variable) and you can have as many arguments as you like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction(name):
    print(f"Hello {name}")

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

&lt;/div&gt;



&lt;p&gt;When we call the function we pass along the information we want used as our argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction(name):
    print(f"Hello {name}")

myFunction("Bobby") # prints Hello Bobby
myFunction("Cade") # prints Hello Cade
myFunction("Scott") # prints Hello Scott
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Keyword Arguments&lt;/strong&gt;&lt;br&gt;
You can also send your arguments in a key = value syntax in python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction(name):
    print(f"Hello {name}")

myFunction(name="Bobby") # prints Hello Bobby
myFunction(name="Cade") # prints Hello Cade
myFunction(name="Scott") # prints Hello Scott
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Default Parameter Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to have a default parameter value for when a function is called without an argument the following syntax is used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction(name="Dan"):
    print(f"Hello {name}")

myFunction("Bobby") # prints Hello Bobby
myFunction() # prints Hello Dan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pass Statement&lt;/strong&gt;&lt;br&gt;
If you have a function written with no code you can use the pass statement to avoid getting an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myFunction():
    pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Dictionaries in Python</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Fri, 05 Feb 2021 00:29:01 +0000</pubDate>
      <link>https://dev.to/scdan0624/dictionaries-in-python-jmi</link>
      <guid>https://dev.to/scdan0624/dictionaries-in-python-jmi</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my previous blog I went over 3 of the built in data sets in Python: lists, tuples, and sets. In this blog we will go over another built in Python data set, dictionaries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Dictionaries?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dictionaries are used to store value in a key:value pairs. Dictionaries are unordered, do not allow duplicates, and can be changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Dictionary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a dictionary we use the follow syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable_name = {key:value}

# example
friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Access a dictionary item&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To access a dictionary item we use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

print(friend_ages["Adam"])  # 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to print the entire dictionary you just use print and the dictionary like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

print(friend_ages)  # {"Rolf": 24,"Adam": 30,"Anne": 27}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Change an Item in a Dictionary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To change an item in a dictionary we use a similar syntax as accessing an item:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

friend_ages["Rolf"] = 21

print(friend_ages["Rolf"]) # 21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add an Item to a Dictionary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add an item to a dictionary we use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

friend_ages["Danny"] = 38

print(friends_ages) # {"Rolf": 24,"Adam": 30,"Anne": 27,"Danny":38}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Delete an Item&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To delete an item in a dictionary we use the &lt;code&gt;pop()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;friend_ages = {
    "Rolf": 24,
    "Adam": 30,
    "Anne": 27
}

friend_ages.pop("Adam")

print(friends_ages) # {"Rolf": 24,"Anne": 27}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Loop Through a Dictionary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally to loop through a dictionary we use a for loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;student_attendance = {"Rolf": 96, "Bob": 80, "Anne": 100}

for student in student_attendance:
    print(student)  # Rolf, Bob, Anne

# print every key value pair

for student in student_attendance:
    print(f"{student}: {student_attendance[student]}")
# Rolf: 96
# Bob: 80
# Anne: 100

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

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>python</category>
    </item>
    <item>
      <title>Lists, Tuples, and Sets in Python</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Wed, 27 Jan 2021 22:37:05 +0000</pubDate>
      <link>https://dev.to/scdan0624/lists-tuples-and-sets-in-python-45jk</link>
      <guid>https://dev.to/scdan0624/lists-tuples-and-sets-in-python-45jk</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lists, tuples, and sets are 3 built in Python data types to store multiple variables. While they may serve the same function, each built in data type has a few key differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The list data types have the following traits: &lt;br&gt;
1.Lists are written with brackets.&lt;br&gt;
2.The items in a list are ordered.&lt;br&gt;
3.The items in the list can be changed.&lt;br&gt;
4.Duplicate items in a list are allowed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a list&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a list we use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;l = ["Bob", "Rolf", "Anne"]
print(l) # prints ["Bob", "Rolf", "Anne"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Print a list item&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Because list items are ordered we print them using an index. The first item has an index of 0 the next item an index of one and so on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(l[0]) # prints "Bob" 
print(l[2]) # prints "Anne" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Change a list element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To change an element in a list you refer to the index number :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;l = ["Bob", "Rolf", "Anne"]
l[0] = "Smith"
print(l) # prints ["Smith", "Rolf", "Anne"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add to a list element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add an element to the end of a list we use the &lt;code&gt;append()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;l = ["Bob", "Rolf", "Anne"]
l.append("Smithy")
print(l) # ['Bob', 'Rolf', 'Anne', 'Smithy']

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remove a list item&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To remove a list item we use the &lt;code&gt;remove()&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;l = ["Bob", "Rolf", "Anne"]
l.remove("Rolf")
print(l) # prints ['Bob', 'Anne']

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The set data type has the following traits:&lt;br&gt;
1.Sets are written with curly braces.&lt;br&gt;
2.Sets are unordered.&lt;br&gt;
3.Sets are not indexed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Set&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a set we use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = {"Bob", "Rolf", "Anne"}
print(s) # prints {"Bob", "Rolf", "Anne"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add item to a set&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add an item to a set we use the &lt;code&gt;add()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = {"Bob", "Rolf", "Anne"}
s.add("Smith")
print(s) # prints {"Bob", "Rolf", "Anne","Smith"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remove item from a set&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To remove an item we use the &lt;code&gt;remove()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = {"Bob", "Rolf", "Anne"}
s.remove("Bob")
print(s) # prints {"Rolf", "Anne"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tuples&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The tuple data type has the following traits:&lt;br&gt;
1.Tuples are written with round brackets.&lt;br&gt;
2.Tuples are ordered.&lt;br&gt;
3.Tuples are not changeable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a tuple&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a tuple we use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t = ("Bob", "Rolf", "Anne")
print(t) # prints ("Bob", "Rolf", "Anne")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Access tuple items&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similar to lists we access tuple items using the index number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t = ("Bob", "Rolf", "Anne")
print(t[1]) # prints "Rolf"

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Now you know how to work with 3 of the 4 built in python data types. Next week we will go over the fourth data type in python dictionaries.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
    </item>
    <item>
      <title>Python Variables</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Fri, 22 Jan 2021 19:38:39 +0000</pubDate>
      <link>https://dev.to/scdan0624/python-variables-162p</link>
      <guid>https://dev.to/scdan0624/python-variables-162p</guid>
      <description>&lt;p&gt;&lt;strong&gt;What Are Variables in Python?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similar to variables in Javascript and other programming languages variables in Python are the names of containers that store values. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables in Python do not have a command for declaration, instead a variable is declared once you assign a value to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 15
y = "Tom"
car = 'Honda'

print(x) // 15 # prints 15
print(y) // Tom # prints Tom
print(car) // Honda # prints Honda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see above if you want to assign a string to a variable you can use either single or double quotes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Changing Variable Values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To change a variable in Python you assign a new value to the same name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 15
print(x) # prints 15

x = "basketball"
print(x) # prints basketball
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Variables are Case Sensitive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just a quick note variable names in Python are case sensitive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = 2
R = "Bob"
#R will not overwrite a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Variable Names Rules in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variable names in Python have the following rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A variable name must start with a letter or underscore character&lt;/li&gt;
&lt;li&gt;A variable name cannot start with a number&lt;/li&gt;
&lt;li&gt;A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )&lt;/li&gt;
&lt;li&gt;A variable name must be case sensitive (See example above)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Intro to Data Structures Part 3, Even More Array Techniques</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Fri, 15 Jan 2021 21:31:37 +0000</pubDate>
      <link>https://dev.to/scdan0624/intro-to-data-structures-part-3-even-more-array-techniques-1cef</link>
      <guid>https://dev.to/scdan0624/intro-to-data-structures-part-3-even-more-array-techniques-1cef</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Over my last two blogs we went over how to create and manipulate arrays through techniques such as &lt;code&gt;push()&lt;/code&gt;, &lt;code&gt;pop()&lt;/code&gt;, &lt;code&gt;slice()&lt;/code&gt;, and &lt;code&gt;splice()&lt;/code&gt;. On this final blog on arrays, we will look at how to combine arrays and how to iterate through arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Combine Arrays&lt;/strong&gt;&lt;br&gt;
One cool feature of the spread operator, that we didn't go over in the last blog, is how to combine arrays. The syntax to combine arrays is very simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ['dog','cat','horse'];
let myNewArray = ['bird',...myArray,'pig','cow']

console.log(myNewArray) [ 'bird', 'dog', 'cat', 'horse', 'pig', 'cow' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the spread operator we easily combined the two arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find the Index of an Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once we start writing long arrays it may be difficult to remember the index location of a certain element. Luckily Javascript has a built in method called &lt;code&gt;indexOf()&lt;/code&gt; that can find the element easily. Here is the syntax for &lt;code&gt;indexOf()&lt;/code&gt; using our previous example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ['dog','cat','horse'];

let myNewArray = ['bird',...myArray,'pig','cow']

myNewArray.indexOf('dog') // 1
myNewArray.indexOf('pig') // 4
myNewArray.indexOf('snake') // -1 Will return -1 if element can't be found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see &lt;code&gt;indexOf()&lt;/code&gt; can be incredible useful for both finding if an element exists and the index it is located at. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iterate Through an Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Very often when working with arrays we may need to iterate through each item. Using a &lt;code&gt;for&lt;/code&gt; loop we can do this easily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArr = ['dog', 'cat', 'whale','snake'];

for(let i = 0; i &amp;lt; myArr.length; i++){
  console.log(`These are the animals in my zoo ${myArr[i]}`)
}

// 'These are the animals in my zoo dog'
// 'These are the animals in my zoo cat'
// 'These are the animals in my zoo whale'
// 'These are the animals in my zoo snake'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see by using a &lt;code&gt;for&lt;/code&gt; loop we were able to iterate through every element in our array and add them to our custom sentence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
After finishing this third blog you are fully prepared to create and manipulate arrays, one of the more commonly used data structure. In our next blog we will look at another common data structure, objects. &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Intro to Data Structures Part 2, More Array Techniques </title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Wed, 06 Jan 2021 23:16:30 +0000</pubDate>
      <link>https://dev.to/scdan0624/intro-to-data-structures-part-2-more-array-techniques-go8</link>
      <guid>https://dev.to/scdan0624/intro-to-data-structures-part-2-more-array-techniques-go8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my last blog we went over how to store and access arrays. We also learned some simple techniques to add and remove items from the beginning and end of an array. In this article we will look at some more advanced array manipulation techniques&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Removing Items Using splice()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Previously we learned how to remove items from the end of an array with 'pop()' and the beginning of an array with 'shift()'. But what if you want to remove items from in-between the beginning and end of an array? Or what if you want to remove more than just one element at a time? This is where we use 'splice()' which allows use to remove any number of consecutive elements from anywhere in the array.&lt;/p&gt;

&lt;p&gt;Splice can take up to three parameters but for this removal lesson will will focus on two parameters. The syntax for 'splice()' with two parameters is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.splice(index, howmany)

// index is where you want to start the splice
// howmany is how many item you want to remove
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For an example lets look at using &lt;code&gt;splice()&lt;/code&gt; to remove some fruit from our array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];


let newArray = myArray.splice(2,1)

console.log(newArray) // [ 'Apple' ]
console.log(myArray) // [ 'Banana', 'Orange', 'Mango', 'Kiwi' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from our example above &lt;code&gt;splice()&lt;/code&gt; can also be use to create a new array with the removed items.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Items Using splice()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our previous lesson we removed items using two parameters. Using a third parameter you can add items using &lt;code&gt;splice()&lt;/code&gt;. Here is the syntax for adding items:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.splice(index, howmanytoremove, items to add)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is an example of removing items from an array and adding a few items in their place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];

myArray.splice(2,1,"Blackberries","Strawberries")

console.log(myArray) // [ 'Banana', 'Orange', 'Blackberries', 'Strawberries', 'Mango', 'Kiwi' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Copying an Array using Slice()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our previous lessons when using &lt;code&gt;splice()&lt;/code&gt; we modify the original array. Using &lt;code&gt;slice()&lt;/code&gt; we can copy an array leaving the original array intact.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;slice()&lt;/code&gt; only takes two parameters, the first is the index where the extraction begins and the second is the index where to stop the extraction. One key thing to remember is for that second number the extraction will occur up to but not including that element. Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
let myNewFruit = myArray.slice(1,3)

console.log(myNewFruit) // [ 'Orange', 'Apple' ]

console.log(myArray) // [ 'Banana', 'Orange', 'Apple', 'Mango', 'Kiwi' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice in the example above we created an new array without changing the original.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we know how to remove and add items to any part of array. In our next lesson we will take a look at some more array manipulation techniques.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>array</category>
    </item>
    <item>
      <title>Intro to data structures part 1 Arrays</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Mon, 04 Jan 2021 22:04:50 +0000</pubDate>
      <link>https://dev.to/scdan0624/intro-to-data-structures-part-1-arrays-4n6i</link>
      <guid>https://dev.to/scdan0624/intro-to-data-structures-part-1-arrays-4n6i</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data can be stored and accessed in many different ways in Javascript. In part one we will look how to store, access, and manipulate data in arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Store Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To store data in a non nested array the following syntax is used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["basketball", 1, true ]
console.log(myArray.length); // 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see an array can store multiple data types such as strings, booleans, and numbers. Using &lt;code&gt;.length&lt;/code&gt; you can also see how many items are in the array.&lt;/p&gt;

&lt;p&gt;A more complex array is a nested array where the array contains another array or an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = [
  [1,2,3],[4,5],"test"
]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Access Array Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In an array each array item has an &lt;code&gt;index&lt;/code&gt;. The index acts as the position of the item of the array. Every array index starts at zero and is increased by one. To access the array item we use console.log, followed by the array variable name, followed by a bracket with the index inside:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Robert","Tom","Megan"];

console.log(myArray[0]) // Robert
console.log(myArray[1]) // Tom
console.log(myArray[2]) // Megan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also set an item in an array using &lt;code&gt;bracket notation&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Robert","Tom","Megan"];

myArray[1] = "Tommy"

console.log(myArray) // [ 'Robert', 'Tommy', 'Megan' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add Items to an Array with push() and unshift()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Array.push()&lt;/code&gt; and &lt;code&gt;Array.unshift()&lt;/code&gt; are methods used to quickly add items to an array. &lt;code&gt;Array.push()&lt;/code&gt; adds to the end of an array while &lt;code&gt;Array.unshift()&lt;/code&gt; adds to the beginning of an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Robert","Tom","Megan"];


myArray.push("Bobby")
myArray.unshift("Dwight")

console.log(myArray) // [ 'Dwight', 'Robert', 'Tom', 'Megan', 'Bobby' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remove Items from an Array using pop() and shift()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you would like to remove items from the end of an array use the &lt;code&gt;Array.pop()&lt;/code&gt; method, while using the &lt;code&gt;Array.shift()&lt;/code&gt; method to remove items from the beginning of an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = ["Robert","Tom","Megan"];

myArray.pop() // "Megan"

console.log(myArray) // [ 'Robert', 'Tom' ]

myArray.shift() // "Robert"

console.log(myArray) // [ 'Tom' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are now set to create, access, and modify arrays. In part 2 we will look at more complex array manipulation, including how to copy arrays. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript understanding errors part 2 common error examples</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Sat, 26 Dec 2020 20:20:02 +0000</pubDate>
      <link>https://dev.to/scdan0624/javascript-understanding-errors-part-2-common-error-examples-j4c</link>
      <guid>https://dev.to/scdan0624/javascript-understanding-errors-part-2-common-error-examples-j4c</guid>
      <description>&lt;p&gt;&lt;strong&gt;Into&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In part 1 we went over some common syntax and reference errors that you may come across as a beginning programmer. In part 2 we will go over some more common errors along with some less common but equally important ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting to Close Parenthesis on a Function Call&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you create a function that does not take any arguments, a common error is to forget the parenthesis when you call that function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printNumberFive(){
  let x = 2
  let y = 3
  return x + y;
}

let notFive = printNumberFive; // will set notFive equal to a function but not 5
let five = printNumberFive(); // will set five equal to return x + y of function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Passing Arguments in the Wrong Order&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another common error when dealing with functions is passing/calling the arguments in the incorrect order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function groceryList (array,name){
  return `Hi my name is ${name} and these are my groceries I need to buy ${array}`
}

groceryList("Dan",["Bacon","Eggs","Milk"])
//'Hi my name is Bacon,Eggs,Milk and these are my groceries I need to buy Dan'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just remember the arguments must be called in the same order that they are passed in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function groceryList (array,name){
  return `Hi my name is ${name} and these are my groceries I need to buy ${array}`
}

groceryList(["Bacon","Eggs","Milk"],"Dan")

//'Hi my name is Dan and these are my groceries I need to buy Bacon,Eggs,Milk'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Off By One Error When Indexing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Off by one errors typically occur when looping over indices or targeting a specific index in a string or array. Javascript indices start at zero and a common mistake is to assume they start at 1, leading to the index you are targeting to be off by one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myArray = [1,2,5,10,20,40]

for(var i = 0; i &amp;lt;= myArray.length; i++){
  console.log(myArray[i])
}

// Loops one to many times at the end because there are only 5 indices but i &amp;lt;= myArray.length will attempt to print out 6 indices.

for(var i = 1; i &amp;lt; myArray.length; i++){
  console.log(myArray[i])
}

// Does not print the first number in the array

for(var i = 0; i &amp;lt; myArray.length; i++){
  console.log(myArray[i])
}

// Correctly prints all the numbers in the array

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Knowing these common errors can be a huge time saver. If there are other common errors I missed feel free to comment below, I would love to hear them.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript understanding errors part 1</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Mon, 21 Dec 2020 20:30:04 +0000</pubDate>
      <link>https://dev.to/scdan0624/javascript-understanding-errors-part-1-47k2</link>
      <guid>https://dev.to/scdan0624/javascript-understanding-errors-part-1-47k2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bugs are a common part of coding and understanding various common bugs can be a huge time saver. Lets take a look at some of those common bugs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference Errors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reference errors commonly occur when variables or functions are misspelled or mis-capitalized causing the browser to look for an object that does not exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let wideReceiver = "Jerry Rice";
let runningBack = "Frank Gore";
console.log(`My favorite wide receiver is ${wideReciever}`);

// ReferenceError: wideReciever is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let wideReceiver = "Jerry Rice";
let runningBack = "Frank Gore";
console.log(`My favorite wide receiver is ${wideReceiver}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syntax Errors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Syntax errors occur when the incorrect use of defined syntax is in your code. One of the more common syntax errors are from unclosed brackets, quotes, parentheses, and braces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myArr = [1,2,3,10;
console.log(myArr)

SyntaxError: Unexpected token, expected "," (1:23)

&amp;gt; 1 | const myArr = [1,2,3,10;
    |                        ^
  2 | console.log(myArr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An easy way to avoid this mistake is once an opening character is written to immediately close that character before writing out any additional code:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syntax Errors:Mixed Quotes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Javascript allows the use of both single quotes &lt;code&gt;(')&lt;/code&gt; and double quotes &lt;code&gt;(")&lt;/code&gt;. Just make sure in situations where you use both you don't close one of the quotes too early. Also when using single quote be careful of accidentally opening a second set of single quotes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Incorrect
const myQuote = 'I've had a wonderful day today'

SyntaxError: Unexpected token, expected ";" (1:19)

&amp;gt; 1 | const myQuote = 'I've had a wonderful day today';
    |                    ^

// Correct 
const myQuote = 'I\'ve had a wonderful day today';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Incorrect Assignment Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another common error among beginning programmers is the incorrect assignment operator. Remember that &lt;code&gt;=&lt;/code&gt; assigns a name to a variable while  &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; check for equality. &lt;code&gt;===&lt;/code&gt; checks for strict equality meaning the value and type must be the same. &lt;/p&gt;

&lt;p&gt;Here is an example using an if statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 10;
let y = 20;

if(x = y){
  console.log("These numbers are equal")
}

// "These numbers are equal "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why did the console log "These numbers are equal when 10 clearly does not equal 20? We used the incorrect assignment operator &lt;code&gt;=&lt;/code&gt; thus the console.log will trigger with any y value that isn't set to a "falsy" value.&lt;/p&gt;

&lt;p&gt;To fix this we just need to use the proper &lt;code&gt;===&lt;/code&gt; operator in the if statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 10;
let y = 20;

if(x === y){
  console.log("These numbers are equal")
} else {
console.log("These numbers are not equal")
}

// 'These numbers are not equal'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;That concludes the first set of common errors. In my next blog I will go over some more common errors and even a few less common errors.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Javascript regex part 6 specify number of matches</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Mon, 14 Dec 2020 20:47:58 +0000</pubDate>
      <link>https://dev.to/scdan0624/javascript-regex-part-6-specify-number-of-matches-5d4g</link>
      <guid>https://dev.to/scdan0624/javascript-regex-part-6-specify-number-of-matches-5d4g</guid>
      <description>&lt;p&gt;&lt;strong&gt;How to specify upper and lower number of matches&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Previously when we would look for a specific number of matches we would use the &lt;code&gt;*&lt;/code&gt; sign for zero or more matches and the &lt;code&gt;+&lt;/code&gt; for one or more matches. You can also specify a certain range of patterns with the &lt;code&gt;{}&lt;/code&gt; sign which are called quantity specifiers.&lt;/p&gt;

&lt;p&gt;For example what if we wanted to only match the letter o between 3 and 7 times? Here is how you would code it out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let firstOh = 'oooh';
let secondOh = 'oh';
let searchForO = /o{3,9}h/;

searchForO.test(firstOh) // returns true
searchForO.test(secondOh) // returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to specify lower number of matches only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to only specify the lower number with no upper limit you use the same syntax as above without a second number after the comma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let firstOh = 'oooh';
let secondOh = 'oh';
let thirdOh = 'ooooooooooooooooooooooooh'
let searchForO = /o{3,}h/;

searchForO.test(firstOh) // returns true
searchForO.test(secondOh) // returns false
searchForO.test(thirdOh) // returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to specify an exact number of matches&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to specify only an exact number of matches you will have just one number between &lt;code&gt;{}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;et firstLow = 'Looow';
let secondLow = 'Low';
let thirdLow = 'Loooooooooooooooooooooooow'
let searchForO = /Lo{3}w/;

searchForO.test(firstLow) // returns true
searchForO.test(secondLow) // returns false
searchForO.test(thirdLow) // returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Javascript regex part 5 quick advanced shortcuts</title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Sun, 06 Dec 2020 23:13:55 +0000</pubDate>
      <link>https://dev.to/scdan0624/javascript-regex-part-5-quick-advanced-shortcuts-2hpc</link>
      <guid>https://dev.to/scdan0624/javascript-regex-part-5-quick-advanced-shortcuts-2hpc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In previous blogs we looked at matching ranges of letters and numbers using &lt;code&gt;[]&lt;/code&gt;. Now we will take a look at some shorter syntax for looking at matching a range of letters and numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Matching all letters and numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Previously when we wanted to search for all letter and numbers in the alphabet we had to use &lt;code&gt;[a-z]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;While there isn't a shortcut for letters only, there is a shortcut to search for letters and numbers using &lt;code&gt;\w&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let short = /\w/
let myNumber = 23
let myPlayer = "Jordan"
short.test(myNumber) //true
short.test(myPlayer) // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use &lt;code&gt;/W&lt;/code&gt; if you want to search everything but numbers and letters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let short = /\W/
let myNumber = "45*"
let myPlayer = "Jordan!"
myNumber.match(short) //*
myPlayer.match(short) //!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Match all numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to match all the numbers the shortcut for that is &lt;code&gt;\d&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let movieName = "2002: Not A Space Odyssey";
let numRegex = /\d/g; // Change this line
let result = movieName.match(numRegex).length;

console.log(result) // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to match all non numbers use &lt;code&gt;\D&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let movieName = "2002: Not A Space Odyssey";
let numRegex = /\D/g; // Change this line
let result = movieName.match(numRegex).length;

console.log(result) //21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Javascript regex part 4 searching for patterns in specific positions </title>
      <dc:creator>SCDan0624</dc:creator>
      <pubDate>Sun, 29 Nov 2020 22:50:17 +0000</pubDate>
      <link>https://dev.to/scdan0624/javascript-regex-part-4-searching-for-patterns-in-specific-positions-4hb7</link>
      <guid>https://dev.to/scdan0624/javascript-regex-part-4-searching-for-patterns-in-specific-positions-4hb7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the previous three regex blogs we looked for matches regardless of where they were positioned. You can also look for patterns that are at specific positions in the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Match patterns at the beginning/end of the string&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using the ^ symbol (called an anchor) you can check if the string starts with a specific pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "Larry played basketball today"
let regex = /^Larry/
regex.test(str) //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using the $ symbol (also called an anchor) we can check if the string ends with a specific pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "Larry played basketball today"
let regex = /today$/
regex.test(str) //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using both anchors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using both anchors you can check if a string fully matches a pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let timeIsValid = /^\d\d:\d\d$/.test('12:05');
console.log(timeIsValid); //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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