<?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: Chris Perry</title>
    <description>The latest articles on DEV Community by Chris Perry (@geochronology).</description>
    <link>https://dev.to/geochronology</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%2F343571%2F472ae304-5c5c-4085-bbb8-fce023176a03.png</url>
      <title>DEV Community: Chris Perry</title>
      <link>https://dev.to/geochronology</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/geochronology"/>
    <language>en</language>
    <item>
      <title>Make an object from a 2D array of key-value pairs (bonus: it's a one-liner!)</title>
      <dc:creator>Chris Perry</dc:creator>
      <pubDate>Sun, 04 Apr 2021 02:33:30 +0000</pubDate>
      <link>https://dev.to/geochronology/make-an-object-from-a-2d-array-of-key-value-pairs-bonus-it-s-a-one-liner-367j</link>
      <guid>https://dev.to/geochronology/make-an-object-from-a-2d-array-of-key-value-pairs-bonus-it-s-a-one-liner-367j</guid>
      <description>&lt;p&gt;To make an object from a 2D array of key-value pairs in JavaScript, use the following pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.fromEntries(new Map(arrOfKVPairs))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const groceryInventory = [
  ["apples", 10],
  ["bananas", 7],
  ["oranges", 3],
]

const inventoryObj = Object.fromEntries(new Map(groceryInventory))

console.log(inventoryObj)
// { apples: 10, bananas: 7, oranges: 3 }

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

&lt;/div&gt;



&lt;p&gt;Combine with named destructuring for easy object reference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const groceryInventory = [
  ["apples", 10],
  ["bananas", 7],
  ["oranges", 3],
]

const { 
  apples: APPLES,
  bananas: BANANAS,
  oranges: ORANGES
} = Object.fromEntries(new Map(groceryInventory))

console.log(APPLES)
// 10

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>es6</category>
      <category>programming</category>
    </item>
    <item>
      <title>Regex Cheat Sheet (Javascript Edition)</title>
      <dc:creator>Chris Perry</dc:creator>
      <pubDate>Sun, 04 Apr 2021 01:57:27 +0000</pubDate>
      <link>https://dev.to/geochronology/regex-cheat-sheet-javascript-edition-4l9d</link>
      <guid>https://dev.to/geochronology/regex-cheat-sheet-javascript-edition-4l9d</guid>
      <description>&lt;p&gt;(Originally posted to &lt;a href="https://chris-perry.medium.com/regex-cheat-sheet-javascript-edition-315e6ec1a7d3"&gt;Medium&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;I keep a lot of snippets on my work computer but the one I come back to the most is my regex cheat sheet. I find it so helpful that I’m posting it here for others to enjoy as well.&lt;/p&gt;

&lt;p&gt;(Pasting in monotype to preserve markdown formatting)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==================
REGEXP CHEAT SHEET
==================

By @geochronology - https://github.com/geochronology


Methods
-------

## test()

Checks if regex matches var

Syntax: regex.text(var)

`myRegex.test(myString)`


## match()

Returns array of pattern matches
  * Without /g, only returns first match
  * With /g, returns all matches

Syntax: var.match(regex)

`/regex/.test('string');`


## replace()

Swaps occurences of a regex with something else

* With plain text: wrongText.replace(silverRegex, "blue");
  // returns "The sky is blue"

* With capture groups: "Code Camp".replace(/(\w+)\s(\w+)/, '$2 $1');
  // returns "Camp Code"




Flags
-----

## /i

Ignore case


## /g 

Global match




Shorthands
---------------

## \w

Equivalent to [A-Za-z0-9_]

`/\w+/` // returns one or more alphanumeric char


## \W

Excludes all alphanumeric chars (opposite of \w)


## \d

Any digit. Equivalent to [0-9]


## \D

Any non-digit. Equivalent to [^0-9]


## \s

Any whitespace. Equivalent to [ \r\t\f\n\v]


## \S

Any non-whitespace. Equivalent to [^ \r\t\f\n\v]




Character Groups
---------------------

## [...]

Character group. Checks to see if it matches one of the characters in the group.

`/h[au]m`


## [a-z]

Character range. Checks if it matches any character within the range.


## [1-6]

Number range. Checks if it matches any number within the range.


## [a-z0-9]

Letter and number range. Checks if it matches either of the ranges.


## [^abcd]

Negated character set. Specifies characters you dont want to match.


## (abc|def)

Check if one of the enclosed patterns occurs

`/che(ese|ss)/`   // matches "cheese" or "chess"


## (?:..)?

Optional group. Matches the enclosed pattern 0 or 1 time(s).

`/^(?:1 )?\(\d{3}\) \d{3}-\d{4}$/`    

// matches "1 (555) 555-5555" and "(555) 555-5555"




Symbols
------------

## .

Wildcard character. Matches any one character.

`/hu./`


## +

Match one or more occurence. Identifies characters that repeat themselves.

`/a+/`


## *

Match a character that occurs 0 or more times.

With one char:
`/fi*/`:
  "fig"    // returns "fi"
  "foot"   // returns "f"
  "leslie" // returns null

With char range:
`/f[aeiou]*g/`


## ^

Starts with


## $

Ends with




Patterns
-------------

## /^moose/

Searches for pattern at the beginning of strings


## /moose$/

Searches for pattern at end of string


## /(...)\1/

Creates a capture group of stuff inside the parens

Each number refers to each subsequent capture group created




Operators
--------------

## | (or operator)

Match one of 2 or more options. 

/moose|notMoose/
/moose|notMoose|possiblyMoose/


## ? (lazy matching)

Returns the shortest possible matching string. (Default is longest possible.)

"plumply":

`/p[a-z]*l/`   // returns "plumpl"
`/p[a-z]*?l/`  // returns "pl"


## ? (optional character)

Says preceding character is optional. (Useful for British english)

`/colou?r/`


## {x, y} (quantity specifiers)

Specifies range of times something gets repeated (min, max)

* Range: `/a{3,5}h/`
* Lower only: `/a{3,}h/`
* Exact: `/a{3}h/`


## (?=...), (?!...)  (positive/negative lookaheads)

Looks ahead to see if pattern is/isnt there

`(?=bucket)` // looks for bucket
`(?!bucket)` // looks not for bucket

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>regex</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
