How to sort an array of strings in Javascript #shorts

preview_player
Показать описание

My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets
Рекомендации по теме
Комментарии
Автор

If someone needs to sort numbers, this arrow function can help you
(a, b) => a - b
Edit: don't use this if an array includes NaN or Infinity

dkorjey
Автор

The more I see Javascript the more I love C#

Festivejelly
Автор

Woah, thank you man, I never really focused much on sorting and didn't know this existed.

thatsalot
Автор

Awesome video like always ! Keep it up bro.

armandopenatamayo
Автор

I also recommend toLocaleLowercase, if you're sorting case-insensitively.

accidentalengineering
Автор

Done these sorts countless times but never knew about LocaleCompare. Such a great tip!

John-Dennehy
Автор

It is not local. The word is “locale”. As in how does text compare in the locale of the user.

Steve-Richter
Автор

I have just recently learned that if you pass no argument at all to .sort it will sort its elements alphabetically!

Creepystutorials
Автор

Instead of doing the - or b.localeCompare(b), an Array.reverse is also really fast and a bit more explicit.

it_is_ni
Автор

Can we use just like:
array.sort((a, b) => a.localCompare(b));
Right?
(I mean don't use braces)

dkorjey
Автор

it really helps if you use a and z that way in your head you realize its sorting from a-z alphabetically

TheBarthinator
Автор

Looks good, do a video to sort without using sort

King_Eke
Автор

this is my fifth year on JavaScript bit still don't understand what it all about, I think you guys are doing magic if not I have put all my efforts to understand but still can't comprehend it, please save a brother

Arewapro
Автор

The array can be shuffled by passing () => Math.random() - 0.5; I think the shuffledness can be changed by changing the constant.

Pacvalham
Автор

Here is an interesting problem:
Given an array A, sort the contents of a second array B such that elements of B appear in the same order as in array A. Append any element of B not found in A to the end.

Martinit
Автор

Noob question: if using const and that implies constant should that mean we shouldn't be adjusting the value?

youtubewts
Автор

Sir i am confused because arr.sort() should do it, so is there a problem with this method or this video is for learning purpose (i mean should we avoid arr.sort() and do this way …)

Saadkhan-gxeo
Автор

More practically, just import lodash. Also comes with other useful utility functions.

nathanmurphy
Автор

is there a way to do a custom sort with a string. Like if I know what order I want the strings to be in.

PrzGaming
Автор

Is this a forloop? I learned them yesterday from my teacher and he used this same example just different code

dannyspell