avatarDr. Derek Austin 🥳

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

7237

Abstract

ing the media world in a fairly unique and trusting way for months now. Most public figures in his position have people advising them on media strategy, what to say, and what not to say — how to frame things so you are not misquoted. Which interviews to take on and which to refuse. Moreover, probably not to allow two solid days behind the scenes to someone who you think may have an agenda.</p><p id="2ef6">As far as I can tell, he doesn’t have this and has embraced and is fully living out his own dictum — “speak the truth and let the pieces fall where they may”.</p><p id="21b3">So far speaking the truth has worked out well for him — he was lucky that Channel 4 News put up the Cathy Newman interview unedited — a decision I’m sure that they quickly regretted. <b>This New York Times piece feels different </b>— that it will solidify impressions of him on either side.</p><p id="6328"><b>“Bad faith changes everything”</b></p><p id="cf22">As Eric Weinstein, Bret’s brother, and another member of the unofficial ‘intellectual dark web’ said — “bad faith changes everything”. It’s possible to have any kind of discussion with people you disagree with so long as they are approaching it in good faith — as soon as they are not, they’re just looking to boost their position, look good in front of others or advance their career within their tribe — as Peterson alleged Cathy Newman was — then true exchange of ideas is impossible.</p><p id="c6f9">I would argue that this journalist is indeed acting in bad faith. Some of the misrepresentations cannot be put down to simple misunderstanding.</p><p id="7c74">The piece of the interview that has been seized upon is this:</p><blockquote id="f129"><p>“Recently, a young man named Alek Minassian drove through Toronto trying to kill people with his van. Ten were killed, and he has been charged with first-degree murder for their deaths, and with attempted murder for 16 people who were injured. Mr. Minassian declared himself to be part of a misogynist group whose members call themselves incels. The term is short for “involuntary celibates,” though the group has evolved into a male supremacist movement made up of people — some celibate, some not — who believe that women should be treated as sexual objects with few rights. Some believe in forced “sexual redistribution,” in which a governing body would intervene in women’s lives to force them into sexual relationships.</p></blockquote><blockquote id="8111"><p>Violent attacks are what happens when men do not have partners, Mr. Peterson says, and society needs to work to make sure those men are married.</p></blockquote><blockquote id="005a"><p>“He was angry at God because women were rejecting him,” Mr. Peterson says of the Toronto killer. “The cure for that is enforced monogamy. That’s actually why monogamy emerges.”</p></blockquote><blockquote id="f00b"><p>Mr. Peterson does not pause when he says this. Enforced monogamy is, to him, simply a rational solution. Otherwise women will all only go for the most high-status men, he explains, and that couldn’t make either gender happy in the end.”</p></blockquote><p id="4fb7">The framing of it makes it sound like he’s advocating for some kind of “government/state enforced” monogamy — which is malicious. He — as anyone who has been listening to his lectures will tell you — is making a more subtle point.</p><p id="924a">That monogamy is an evolved trait to stabilise societies — it’s “enforced” only as a social rule. Many societies in the past have had polygamy or other situations where a small number of men had access to many women (as do many animal societies), and that proved to be unstable and a bad long term solution to social harmony.</p><p id="7529">So in this argument, the reason that monogamy evolves (and is socially enforced) is to avoid the kind of situation where you end up with too many bitter young men wanting to tear things down. Which — whether you agree with his reading or not — seems to be happening.</p><p id="c544">And he also argues — that one of the consequences of the sexual revolution of the 60s is that it has loosened sexual behaviour. When that happens, and there are less social and physiological downsides (pregnancy is not inevitable) — and more sex is being had — the spoils go disproportionately to the most attractive men.</p><p id="7716">He is arguing that there are deeper reasons for the morality that we evolved over our history, and that there are consequences to the kinds of lifestyle experiments that we saw start to accelerate in the 1960s. This is what the essence of Peterson’s message is about.</p><p id="fb0d">You can disagree with Peterson, but many people are recognising that this fits their experience of the world — hence his popularity. That the increasingly boundary-less world we’ve created is not working and we need a reintegration of these traditional values.</p><p id="ad84"><b>Ideological fixation</b></p><p id="89ce">Personally I agree with Peterson that much of our culture and media is in the grip of an ideology that styles itself as open, inclusive and tolerant, but actually has a shadow side of intolerance towards those that don’t share their values.</p> <figure id="3404"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FaMcjxSThD54%3Fstart%3D1511%26feature%3Doembed%26start%3D1511&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaMcjxSThD54&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FaMcjxSThD54%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854"> </div> </div> </figure></iframe></div></div></figure><p id="731c">One of the sacred cows in this is the belief that the only reason that men and women don’t have equal representation in many industries and top jobs is because of discrimination, not differing choices. This was famously the subject of the clash with Cathy Newman.</p><p id="fc16">If these activists (and the liberal left generally) has to accept that there are measurable differences in temperament, values and life choices made by men and women, and that some of them are likely tied to biology and evolutionary history — then the entire edifice of this ‘gender ideology’ movement starts to shake. We would realise that it would be irrational to expect 50/50 representation in many jobs, for example.</p><p id="8022">And realise that this is not just a social movement — this ideological framing — it’s a big industry. There are charities, organisations and groups that are funded on the basis of this that have huge impact on the media conversation, and business practice.</p><p id="e742">So left-wingers who are usually concerned about the impact of money on ideology and political decisions from corporate interests, might wish to look at the fact that these are major financial interests as well. It is not possible for this entire industry to look at the data accurately.</p><p id="b543">I would also frame it in this way that might resonate

Options

with left-wing thinkers. Why are you using capitalist metrics like pay to decide on whether women have achieved equality? Isn’t that just another version of the ‘patriarchy’ controlling your minds? How has “the man” persuaded you that equal pay is the right metric to look for equal respect and value?</p><p id="b245">What makes women actually fulfilled and gives genuine meaning in life? Is it the same as for men? I doubt it, and I personally know many women who made that realisation too late in life to easily have a balanced life that included children.</p><p id="5cc1">But anything that argues against leftist ideology is attacked and smeared. For example the infamous ‘Google memo’ was a case in point, being described as an ‘anti-diversity screed’ throughout the media despite the author, James Damore, specifically making suggestions that would increase the representation of women in tech. This article from the Atlantic — from a writer who doesn’t agree with Damore’s conclusions — gives good context to its misrepresentation: “To me, the Google memo is an outlier — I cannot remember the last time so many outlets and observers mischaracterized so many aspects of a text everyone possessed.”</p><p id="3999">Liberalism as an ideology, with those inside and outside the tribe. Those outside the tribe, like Peterson — deserve scorn, derision, and even misrepresentation.</p><p id="11cc">Another hard to explain mischaracterisation, if the journalist had any familiarity with Peterson’s work is this:</p><blockquote id="33b8"><p>“Mr. Peterson illustrates his arguments with copious references to ancient myths — bringing up stories of witches, biblical allegories and ancient traditions. I ask why these old stories should guide us today.</p></blockquote><blockquote id="f195"><p>“It makes sense that a witch lives in a swamp. Yeah,” he says. “Why?”</p></blockquote><blockquote id="69ec"><p>It’s a hard one.</p></blockquote><blockquote id="0ac8"><p>“Right. That’s right. You don’t know. It’s because those things hang together at a very deep level. Right. Yeah. And it makes sense that an old king lives in a desiccated tower.”</p></blockquote><blockquote id="fc08"><p>But witches don’t exist, and they don’t live in swamps, I say.</p></blockquote><blockquote id="e8f8"><p>“Yeah, they do. They do exist. They just don’t exist the way you think they exist. They certainly exist. You may say well dragons don’t exist. It’s, like, yes they do — the category predator and the category dragon are the same category. It absolutely exists. It’s a superordinate category. It exists absolutely more than anything else. In fact, it really exists. What exists is not obvious. You say, ‘Well, there’s no such thing as witches.’ Yeah, I know what you mean, but that isn’t what you think when you go see a movie about them. You can’t help but fall into these categories. There’s no escape from them.”</p></blockquote><p id="3287">He is deliberately framed here as an old crank, an eccentric who believes in dragons and witches. Yet throughout his lectures he has made clear he is talking psychologically, archetypally and mythologically.</p><p id="67f0">In this view they exist in our mythology in a very real way as representations of psychological realities, for example that the dragon is the mythological representation of the ‘unknown’. Throughout our history if you ventured out into the unknown you could die — but there was no other way to discover new information or new rewards.</p><p id="cc2a">So the dragon is a composite predator of all the animals that used to prey on humans — a cat/snake/bird — and of course in mythology dragons have gold (or virginal women in captivity). The deep psychological story is that by confronting the unknown, you can achieve riches. He’s made that abundantly clear in every lecture.</p><p id="2105">What is becoming ever clearer (and again is something Peterson points out) — the death spiral of the print media is speeding up polarisation — in even the most reputable organisations such as the New York Times start to produce clickbait such as the Jordan Peterson article.</p><p id="4e32">Perhaps the New York Times have decided to take a leaf out of the book of the 4chan culture, and provocateurs like Milo Yiannopolous who made whole careers out of provoking the left into overreaction. In this case — the NYT have placed this article behind a paywall (I’m told) — so to read it, outraged Peterson fans will have to subscribe to the paper.</p><p id="255f">Then to unsubscribe — I know because I just checked — you cannot unsubscribe online, you have to call them. This seems at least unethical.</p><p id="5aaf">The most dangerous part of this whole enterprise is that Peterson has now become pretty much the singular focus of the ramping up of the culture wars — the lightning rod, if you will. Articles like this add hugely to the polarisation he warns about.</p><p id="46ed">On one side you have literally tens of thousands of people (mainly, but not all men) who have had their lives changed, and many claiming actually saved, by listening to Jordan Peterson’s words. On the other side you have a mix of hard core ideological opponents to him, and a vast middle ground who don’t know him well — but are almost certainly thinking that there is no smoke without fire.</p><p id="6c75">He has argued frequently that we are in an increasingly polarised world and that individual actions can have serious consequences, if we don’t act with integrity, or we sacrifice our morality and conscience in any way.</p><p id="c074">This journalist spent two days with Peterson in his house, she seemingly has some familiarity with his work, and yet chooses to characterise him in this way.</p><p id="9c1a">The treatment of Jordan Peterson is speeding up the irrelevance of the mainstream media at an increasing rate. Too many people are aware of his work and who he is and what he believes for the hit pieces to stick.</p><p id="3463">In the language of the internet subculture — the treatment of Jordan Peterson by the mainstream media is showing up their ideology, and Red Pilling an entire generation.</p> <figure id="41f6"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYDxl1stMTCU%3Fstart%3D193%26feature%3Doembed%26start%3D193&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYDxl1stMTCU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYDxl1stMTCU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854"> </div> </div> </figure></iframe></div></div></figure><p id="8453">For more documentaries and interviews, check out the <a href="https://www.youtube.com/channel/UCFQ6Gptuq-sLflbJ4YY3Umw?view_as=subscriber">Rebel Wisdom Youtube channel</a>.</p><p id="0b51">My personal website: <a href="http://davidfuller.tv/">http://davidfuller.tv/</a></p><p id="a4b2">And please consider <a href="https://www.patreon.com/rebelwisdom">supporting us on Patreon</a>.</p></article></body>

How to Use Set in JavaScript ES6 to Find Unique Items

Need unique values in JavaScript? That’s where the Set object comes in. Here’s how to use Set to filter a list of unique primitive values, objects by reference, or objects by their contents (values).

Photo by Stephen Leonardi on Unsplash

Unique JavaScript Values? Think Set

A Set is a unique collection of items, and it has the advantage over JavaScript objects that you can iterate through the items of a Set in insertion order.

“The Set object lets you store unique values of any type, whether primitive values or object references.” — MDN Docs

In other words, you can loop through a Set like an array, and the items stay in the order that they were found in. The properties of a JavaScript object do not retain their insertion order, so the order the properties were added to an object is lost in translation if use try to filter unique items using an object.

Set is an ES6 feature supported in all modern browsers, including IE11, according to the page for Set() on CanIUse.com.

In this article, you’ll learn how to use Set to handle the common task of finding a list of unique items in an array, whether you need to find unique primitive values (like numbers or strings) or objects.

I’ll cover both using Set with object references (the default behavior) as well as with the contents of those objects (finding unique objects by value).

Photo by Andrew Tanglao on Unsplash

How Set Checks Value Equality

Set uses the triple equality operator (===) also known as the strict equality operator in order to check equality of primitive values or objects.

“A value in the Set may only occur once; it is unique in the Set's collection.” — MDN Docs

However, there are a few key differences with the implementation of equality comparison for Set versus ===, at least since ECMAScript 2015 (ES6).

For Set, +0 (positive zero) and -0 (negative zero) are considered to be the same value, even though +0 !== -0 in JavaScript.

Similarly, Set treats NaN (not-a-number) differently than ===, in that Set makes all NaN values equal and will only store one in the Set.

NaN is typically the only value that does not equal itself in JavaScript, meaning that NaN === NaN is false and NaN !== NaN is true.

For details on how NaN works, see my article about How to Check for NaN:

Undefined values (undefined) can also be stored in a Set, and again only one undefined value will be kept. That’s normal behavior for ===, though.

Taken together, the behavior of Set is a little bit closer to that of another ES6 feature Object.is() compared to ===.

Photo by Josh Carter on Unsplash

Using Set for Unique Primitive Values in an Array

Using Set is straightforward, as far as JavaScript objects go: you call the Set() constructor with the new keyword: new Set() // Set [].

The equivalent to the .push() method of arrays (Array.prototype.push()) for a Set is called .add() (Set.prototype.add()). It works the same way — except that only one of each unique value will be added to the Set.

That means you could loop through an array using .forEach() (Array.prototype.forEach()) or a for...of loop, then .add() each item to a new Set. The resulting Set object will have only the unique values.

More simply, you can just pass the array to the Set() constructor directly. That works because the Set() constructor accepts an iterable object, like an array, as its sole parameter.

“[JavaScript’s] iterable objects [include] built-in String, Array, array-like objects (e.g., arguments or NodeList), TypedArray, Map, Set, and user-defined iterables.” — MDN Docs

The constructor’s parameter is optional; new Set() makes an empty Set.

To convert a Set back to an array, one method to do so is Array.from(). I’ll talk about another method using the spread operator (...) later, but the Array.from() method works just as well and is easy-to-read.

Here is a code snippet demonstrating using Set with primitive values, like numbers and strings, to find the unique values in a JavaScript array.

View raw code as a Github Gist

Did you like the one-liner to find the unique items in an array using Set?

View raw code as a Github Gist

Yeah, me too! 🤩 Thanks ES6.

Note that the order of the resulting Set or array is the “insertion order” — the order that the values were found in the original array or list.

Photo by Tom Gainor on Unsplash

Unique Object References in an Array Using Set

When working with primitive values like numbers or strings, a Set object works just as you would expect it does — only unique values are retained.

However, when working with objects, any objects that contain the same data are considered to be different objects by Set because they have different object references — the actual “pointers” in memory to those objects.

To put it another way, an array with just the number 1 in it will never equal another array, even if it also only contains 1: [1] !== [1] // true

However, we can still use Set to find unique object references in an array or other iterable object. That is super useful if the same object may have been added multiple times to an array, and we only want the unique objects.

For example, if you assign an object to a variable, and then add that variable to an array repeatedly, you could use Set to remove the duplicates:

View raw code as a GitHub Gist

Understanding the concept of object references in JavaScript is something I’ve tackled before, in my article on deep copying objects in JavaScript:

Later in this article, I’ll talk about using Set to compare objects by the values they contain instead of the object references pointing to them.

Photo by Kevin Bree on Unsplash

How to Make an Array From a Set

My favorite method to turn a Set into an array is using the (...) spread operator with a pair of square brackets []: [...mySet].

You can even write it as a one-liner:

View raw code as a GitHub Gist

Wow! Of course, using the (...) spread operator is exactly equivalent to the Array.from() method I was using before. Feel free to use either one.

Once you have an array, you can iterate through it with your usual array methods, like a for...of loop, .forEach(), .map() and .reduce().

You can also iterate through the Set directly, as I discuss in the next section, because a Set is also a type of iterable object, just like arrays themselves.

Photo by Hugo Kruip on Unsplash

Iterating Through a Set of Unique Values

There are a couple basic ways for iterating through a Set in JavaScript, but they’re not quite the same methods you would use for arrays:

1 — Use Set.prototype.keys() or Set.prototype.values()

These two methods are equivalent; both return a new Iterator object including the values for each element in the Set in insertion order.

Having an Iterator object allows us to call the .next() method directly, if that is something you would need to do in your JavaScript code.

Arfat Salman has a nice article explaining iterators over on CodeBurst.io.

2 — Use Set.prototype.forEach() with a Callback Function

The .forEach() method for a Set is similar to the method of the same name for arrays, so you can call it directly on a Set object.

“[.forEach() calls] callbackFn once for each value present in the Set object, in insertion order. If a thisArg parameter is provided, it will be used as the this value for each invocation of callbackFn.” — MDN Docs

Of course, you can use an arrow function as the callback function, the same as you would do when working with an array.

3 — Use a for...of Loop Directly With the New Set

As Set is a type of iterable object, a for...of loop will work the same way with a Set as it would with a JavaScript array.

Technically, you don’t need to change the Set back into an array at all, depending on what task you’re trying to solve.

If you just need to iterate through the list of unique items, then any of these three methods will let you do that, without making a new array in memory.

Here’s a code snippet showing how to use each of the three methods:

View raw code as a GitHub Gist

Typically, to iterate through a Set object directly, I’ll choose the for...of loop, but there’s nothing wrong with the other options.

Photo by Josh Carter on Unsplash

Unique Object Keys (Properties) or Values with Set

To find a list of all the unique keys or unique values on an object, you can combine Object.keys() or Object.values(), respectively, with the Set() constructor, as those methods each return an Iterator object.

That being said, you would probably only ever use Object.values(), because JavaScript object keys are required to be unique in the first place.

“JavaScript objects cannot have duplicate keys. The keys must all be unique.” — Jason Anders from TreeHouse

If you need to save the key associated with each value based on some certain criteria, you should be aware of the Object.entries() method, which returns key-value pairs as an iterable that can be looped through with for...of.

That said, the only use for Set when working with object properties or values is for finding the unique values contained within an object.

View raw code as GitHub Gist

Set lets you find all the unique values in a JavaScript object, if that’s what you need to do — just combine it with Object.values(), as shown above.

Photo by Sandra Seitamaa on Unsplash

Using Set with an Array of Objects: Unique Values

If you have an array of objects instead and need to find the unique values of one object property across all of those objects, you can do it with Set.

Here, you’ll need to use .map() (Array.prototype.map()) to create a new array of only the values you want, and then you make a Set of those.

To break it down, first you map the array of objects to a new array of just the values for your target property.

Then, you apply the Set() constructor as usual to find the unique values:

View raw code as a GitHub Gist

The code above outputs the unique values for the “year” property among all the objects contained in the initial array.

Photo by Peter Scholten on Unsplash

Using Set with an Array of Objects: Unique Objects

If you need to find all of the unique objects in an array based on whether they share the exact same keys and values (their contents), you can use Set.

However, Set checks for object references by default, so you will need to take a different approach in order to use Set.

You can find unique objects in an array by using Set() combined with the JSON helper methods JSON.stringify() and JSON.parse().

View raw code as a GitHub Gist

The above code loops through the entire array of objects, checking to see if the Set already contains the “JSON stringified” version of the object. If it doesn’t, then the object is added to the Set and the output array.

I then simplified my code by using JSON.parse() to transform the strings back to objects. That in turn lends itself to a functional programming approach: using .map()(Array.prototype.map()) instead of a for...of loop.

So, there’s a one-liner to find the unique objects in an array using Set:

View raw code as a GitHub Gist

Just be warned that you may experience some problems using certain values like undefined and Infinity that are not JSON-safe, as I discussed in my previous article about JSON.stringify() and JSON.parse():

That said, for most types of data, JSON will work for comparing the objects using Set, even for nested objects — just watch out for when it doesn’t.

Photo by NOAA on Unsplash

Finding the Unique Dates in an Array Using Set

Let’s expand on our discussion of using Set to find unique Javascript objects by looking at comparing dates using the built-in Date object.

By default, the Date will include an exact timestamp, because a Date is a wrapper for the number of milliseconds since 1 January 1970 UTC. That means any two dates that are off by a millisecond are different.

Additionally, we can’t even use JSON.stringify(), because Date objects are not JSON-safe. Date objects get transformed to strings by JSON.parse(), so you’d have to call the Date() constructor on each one, perhaps by using .map(dateString => new Date(dateString)). Putting that all together, we’d still be comparing milliseconds.

What if we just want to compare the year, month, and day? (The date?)

To find unique dates, you’d need to call .toDateString() (Date.prototype.toDateString()) instead of JSON.stringify().

The .toDateString() method returns the date in a human-readable string, like "Thu Jan 01 3001", making it perfect for the comparison we want.

View raw code as a GitHub Gist

The one-liner for comparing dates is different than the one to compare objects; .map() needs to call .toDateString() and then the Date() constructor with new instead of JSON.stringify() and JSON.parse().

Photo by Ronald Diel on Unsplash

Conclusion

The ES6 feature Set is useful any time you need to filter out duplicate values from an array or other list of items that you’re working with in JavaScript.

Using Set has some built-in advantages over writing your own loop using the strict equality operator ===. Specifically, NaN (not-a-number) will only show up once, and -0 (negative zero) will be considered the same as +0.

Set can be used to find unique object references, to find unique object values, or to find unique object values for a given property in an array of objects.

With some help from JSON.stringify() and JSON.parse(), Set can be used to find unique objects by their contents — as long as the data is JSON safe.

I also included examples of using Set with Date objects, where you might want to compare them by their .toDateString() methods.

One more thing to mention here is Map, the ES6 type that is an iterable version of JavaScript objects, but that’s beyond the scope of this article.

Hopefully, this article has shown you some ways to use Set in JavaScript to filter out duplicate values and only keep the unique primitives or objects.

Happy coding! 👍😆💯

Join my email list to get free access to all of my Medium articles.

Photo by Alex Azabache on Unsplash

Dr. Derek Austin is the author of Career Programming: How You Can Become a Successful 6-Figure Programmer in 6 Months, now available on Amazon.

JavaScript
Software Engineering
ES6
Programming
Web Development
Recommended from ReadMedium