Javascript ( ES14 ): toSorted()

Mai 19, às 03:22


2 min de leitura


0 leituras

ECMAScript proposal "Change Array by copy" by Robin Ricard and Ashley Claymore has been merge into ECMAScript standard. This proposal brings a lot of new toys, one of which is new array method:...
Javascript ( ES14 ): toSorted()

ECMAScript proposal "Change Array by copy" by Robin Ricard and Ashley Claymore has been merge into ECMAScript standard. This proposal brings a lot of new toys, one of which is new array method: toSorted().

The toSorted() method is similar to sort

// Functionless
// Arrow function
toSorted((a, b) => { /* … */ })

Enter fullscreen mode Exit fullscreen mode

The only difference is that it does not change the original array, calling this method returns a changed copy of the original array.


const arr = [3, 4, 2, 5, 1];
// [1, 2, 3, 4, 5] Returns a reference to original array, now sorted
// [1, 2, 3, 4, 5] The original array is mutated

Enter fullscreen mode Exit fullscreen mode


const arr = [3, 4, 2, 5, 1];
// [1, 2, 3, 4, 5] Returns a new copy of arr that is sorted
// [3, 4, 2, 5, 1] The original array is not affected

Enter fullscreen mode Exit fullscreen mode

For more information, check out the following resources:

Continue lendo

Hacker News

Atomic Wallet exploited, users report loss of entire portfolios
Several users on Twitter have reported losses of crypto assets, claiming funds held on the Atomic Wallet app vanished. 10886 Total views 75 Total shares Atomic Wallet has been apparently exploited, with...

Hoje, às 01:41

Hacker News

It Will Cost Up to $21.5 Billion to Clean Up California’s Oil Sites. The Industry Won’t Make Enough Money to Pay for It.
An expert used California regulators’ methodology to estimate the cost of cleaning up the state’s onshore oil and gas industry. The study found that cleanup costs will be triple the industry’s projected profits.

Hoje, às 01:01


How to Create an Evil Twin Access Point; Step-by-Step Guide
Step-by-Step Guide: Creating an Evil Twin An Evil Twin Access Point is a malicious wireless access point that is set up to mimic a legitimate one. It can be used to intercept sensitive information such as...

Jun 3, às 23:41


200 anos em 2 mêses: Usando o ChatGPT para auxiliar na criação de um mundo de fantasia. · MarquesJr
Não, eu não pedi pra Gepeto (ChatGPT) criar um mundo fictício de fantasia pra mim e pronto, nem tão pouco incentivo essa prática e também não irei passar uma fórmula mágica. Nesse artigo...

Jun 3, às 23:07


Atomic Design: A Methodology for Building Design Systems
Introduction Atomic Design is a methodology for creating design systems that recognizes the need to develop thoughtful design systems, rather than creating simple collections of web pages. In this approach,...

Jun 3, às 23:04

Hacker News

Thought Cloning: Learning to Think while Acting by Imitating Human Thinking
Language is often considered a key aspect of human thinking, providing us with exceptional abilities to generalize, explore, plan, replan, and adapt to new situations. However, Reinforcement...

Jun 3, às 23:00

AI | Techcrunch

YouTube rolls back its rules against election misinformation
YouTube was the slowest major platform to disallow misinformation during the 2020 U.S. election and almost three years later, the company will toss that policy out altogether. The company announced Friday...

Jun 3, às 22:57


Techinical Debt; what is it?
Imagine you're building a house. You want to finish it quickly, so you take some shortcuts along the way. You use low-quality materials, skip some important steps, and don't do thorough testing. The house is...

Jun 3, às 22:45

Marktechpost AI Research News

Researchers From UT Austin and UC Berkeley Introduce Ambient Diffusion: An AI Framework To Train/Finetune Diffusion Models Given Only Corrupted Data As Input
For learning high-dimensional distributions and resolving inverse problems, generative diffusion models are emerging as flexible and potent frameworks. Text conditional foundation models like Dalle-2, Latent...

Jun 3, às 22:40

Hacker News

Scientists may be able to put Mars-bound astronauts into 'suspended animation' using sound waves, mouse study suggests
Ellen Ripley (played by Sigourney Weaver) places herself into suspended animation in the 1979 movie Alien. (Image credit: AJ Pics/Alamy Stock Photo) Scientists have blasted the brains of mice and rats...

Jun 3, às 22:38