Тёмный

JavaScript filter() method in 6 minutes! 🚰 

Bro Code
Подписаться 2 млн
Просмотров 14 тыс.
50% 1

// .filter() = creates a new array by filtering out
// elements with a callback
00:00:00 example 1
00:02:13 example 2
00:04:01 example 3
// ---------- EXAMPLE 1 ----------
let numbers = [1, 2, 3, 4, 5, 6, 7];
let evenNums = numbers.filter(isEven);
let oddNums = numbers.filter(isOdd);
console.log(oddNums);
function isEven(element){
return element % 2 === 0;
}
function isOdd(element){
return element % 2 !== 0;
}

Опубликовано:

 

7 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 13   
@BroCodez
@BroCodez 9 месяцев назад
// filter() = creates a new array by filtering out // elements with a callback // ----------- EXAMPLE 1 ----------- let numbers = [1, 2, 3, 4, 5, 6, 7]; let evenNums = numbers.filter(isEven); let oddNums = numbers.filter(isOdd); console.log(oddNums); function isEven(element){ return element % 2 === 0; } function isOdd(element){ return element % 2 !== 0; } // ----------- EXAMPLE 2 ----------- let ages = [16, 17, 17, 18, 19, 20, 65]; let adults = ages.filter(isAdult); let children = ages.filter(isChild); console.log(children); function isAdult(element){ return element >= 18; } function isChild(element){ return element < 18; } // ----------- EXAMPLE 3 ----------- const words = ['apple', 'orange', 'kiwi', 'banana', 'pomegranate', 'coconut',]; const longWords = words.filter(getLongWords); const shortWords = words.filter(getShortWords); console.log(shortWords); function getShortWords(element){ return element.length 6; }
@user-mk2md9pu5m
@user-mk2md9pu5m 8 месяцев назад
Do django course please
@joehaar1466
@joehaar1466 8 месяцев назад
I'm learning Python with your videos. The best material I could find so far. Thank you, bro.
@Aarif6904
@Aarif6904 2 месяца назад
You made the code structure easier for me. Thank you so much brother❤
@xzex2609
@xzex2609 8 месяцев назад
One bad thing about JS is that it works when there is errors and it don't caught errors like python or ... and shows unexpected behavior due to these errors , I wonder if there is any linter for this kind of situation . but believe me it got 30 minutes to find that i had a typo in element.lenght and I did not see it . end everything work like there is nothing but with a bug
@nikolabosevski1435
@nikolabosevski1435 8 месяцев назад
There are some extensions on vs code for linting or you also use typescript which is a bit harder to learn at first but if you know python c++ or any similar language with types you should have no problem. It shows you a lot more errors so it's really useful
@xzex2609
@xzex2609 7 месяцев назад
@@nikolabosevski1435 Thanks a lot for your help , I know there must be some better tools for catching errors. but sometime in the definition of a method is that behave unexpectedly so they are as they are and to avoid such situations i think one should know the behavior of a given method on such situations.
@user-cm8ds7rx6t
@user-cm8ds7rx6t 2 месяца назад
it cool, thanks !😉
@xzex2609
@xzex2609 8 месяцев назад
I use expressions element % 2 for odd or return !( element % 2) , are these expressions are equal like == or strictly === 0 when we don't mention them ??
@kathikr9360
@kathikr9360 3 месяца назад
thank you
@sportsknowledge92
@sportsknowledge92 5 месяцев назад
Please create small small project in js
@nikolabosevski1435
@nikolabosevski1435 8 месяцев назад
One thing about JS that has been a bit confusing is as in your example about isEven function even thoufh it takes a parameter when you define it, when you use it in the .filter method you dont pass an argument in it. Why is that? I have just always taken it for granted but im genuinely curious why it works that way
@julios8228
@julios8228 5 месяцев назад
The parameters are all the elements in the numbers array. The filter function is going to iterate through all the elements of the numbers array and will evaluate the condition in the isEven() function.
Далее
JavaScript reduce() method in 5 minutes! ♻
5:31
Просмотров 20 тыс.
JavaScript map() method in 7 minutes! 🗺
7:01
Просмотров 26 тыс.
The Hardest Challenge!
00:37
Просмотров 10 млн
POLI зовет Газана
00:12
Просмотров 752 тыс.
Learn JavaScript KEY EVENTS in 10+ minutes! ⌨
11:16
Learn JavaScript ARROW FUNCTIONS in 8 minutes! 🎯
8:02
JavaScript forEach() method in 8 minutes! ➿
8:02
Просмотров 24 тыс.
JavaScript Async Await
7:31
Просмотров 803 тыс.
Array Method filter map reduce
9:35
Просмотров 63 тыс.
Python Lambda Functions??
4:30
Просмотров 164 тыс.
Learn JavaScript CLOSURES in 10 minutes! 🔒
10:58
Просмотров 13 тыс.
Build this JS calculator in 15 minutes! 🖩
15:20
Просмотров 409 тыс.
Learn JSON in 10 Minutes
12:00
Просмотров 3,1 млн