JavaScript filter() method in 6 minutes! 🚰

  Рет қаралды 14,038

Bro Code

Bro Code

Күн бұрын

// .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;
}

Пікірлер: 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❤
@user-cm8ds7rx6t
@user-cm8ds7rx6t 2 ай бұрын
it cool, thanks !😉
@kathikr9360
@kathikr9360 3 ай бұрын
thank you
@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 ??
@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 8 ай бұрын
@@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.
@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
Bro Code
Рет қаралды 20 М.
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 4,3 МЛН
Famous Puzzles of Great Mathematicians | Petkovic | Book Review | Beautiful Books | Cheenta
8:29
Cheenta Academy for Olympiad & Research
Рет қаралды 36
JavaScript forEach() method in 8 minutes! ➿
8:02
Bro Code
Рет қаралды 25 М.
Learn Closures In 13 Minutes
13:22
Web Dev Simplified
Рет қаралды 29 М.
Learn CSS Flexbox in easy way
5:05
cssiseasy
Рет қаралды 10 М.
JavaScript map() method in 7 minutes! 🗺
7:01
Bro Code
Рет қаралды 27 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 741 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 153 М.
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27