JavaScript

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๋ฐฐ์—ด(array) filter ํ•จ์ˆ˜์˜ ๊ฐœ๋…๋ฐ ์‚ฌ์šฉ๋ฒ•

martinooo 2024. 6. 28. 16:29

 

 

 

 

 

 

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๋ฐฐ์—ด ์‚ฌ์ „ ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ


 


๋ฐฐ์—ด reduce() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

https://cometruedream.tistory.com/256

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๋ฐฐ์—ด(array) reduce ํ•จ์ˆ˜์˜ ๊ฐœ๋…๋ฐ ํ™œ์šฉ๋„ ๋†’์€ ์‚ฌ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๋ฐฐ์—ด ์‚ฌ์ „ ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ ๋ฐฐ์—ด join() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐhttps://cometruedream.tistory.com/254 [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๋ฐฐ์—ด(array)์„ ์œ ์šฉํ•˜๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” join ํ•จ์ˆ˜ ๊ฐœ

cometruedream.tistory.com

 

 

๋ฐฐ์—ด join() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

https://cometruedream.tistory.com/254

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๋ฐฐ์—ด(array)์„ ์œ ์šฉํ•˜๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” join ํ•จ์ˆ˜ ๊ฐœ๋… ๋ฐ ์‚ฌ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ๋ฐฐ์—ด์€ javascript์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ ์ž๋ฃŒ๊ตฌ์กฐ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.๋ฐฐ์—ด์— ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์€ javascript์—์„œ ์ค‘์š”ํ•œ ๋ถ€๋ถ„ ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ join() ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์„ ํ•ฉ

cometruedream.tistory.com

 

 

๋ฐฐ์—ด map(), forEach() ์ธ๊ธฐ ์žˆ๋Š” ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

https://cometruedream.tistory.com/253

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๋ฐฐ์—ด(array)์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ธ๊ธฐ์žˆ๋Š” ๋ฉ”์†Œ๋“œ map(), forEach() ๊ฐœ๋…๊ณผ ์ฐจ์ด์ 

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ํ˜„์žฌ ์›น/์•ฑ ๊ฐœ๋ฐœ ํŠธ๋ Œ๋“œ์—์„œ ํ•„์ˆ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์•„์ดํ…œ์„ ์ €์žฅํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฐ์—ด๊ณผ ์ด๋ฅผ ํŒŒ์‹ฑํ•˜๋ฉฐ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ

cometruedream.tistory.com

 

 

ํ™œ์šฉ๊ฐ€์น˜๊ฐ€ ์ข‹์€ every(), some() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

https://cometruedream.tistory.com/250

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ํ™œ์šฉ๊ฐ€์น˜๊ฐ€ ์ข‹์€ ๋‚ด์žฅํ•จ์ˆ˜์™€ every(), some() ํ•จ์ˆ˜์˜ ๊ฐœ๋… ๋ฐ ํ™œ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋‚ด์žฅ ํ•จ์ˆ˜๋ž€?์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ํ™œ์šฉํ•˜๋ ค๋ฉด ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์ž˜ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.๋‚ด์žฅ ํ•จ์ˆ˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ฏธ๋ฆฌ ์„ ์–ธ๋œ ํ•จ์ˆ˜๋กœ, ํ˜ธ์ถœ๋งŒ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต

cometruedream.tistory.com

 

 

๐Ÿคท‍โ™‚๏ธ filter ํ•จ์ˆ˜๋ž€?


javascript์˜ filter() ํ•จ์ˆ˜๋Š” ๋ฐฐ์—ด์„ ์ˆœํšŒํ•˜๋ฉด์„œ ํŠน์ • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์š”์†Œ๋งŒ ์ถ”์ถœํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.

filter() ํ•จ์ˆ˜๋Š” ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์ฃผ์–ด์ง„ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์ฝœ๋ฐฑ ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜ ๊ฐ’์ด true์ธ ์š”์†Œ๋งŒ ๋ชจ์•„์„œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

 

filter() ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์ดํ•ดํ•˜๋ฉด

๐Ÿ’ก ๋ฐฐ์—ด์˜ ์ž๋ฃŒ๊ตฌ์กฐ์—์„œ ํŠน์ • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๊ฐ’๋งŒ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ๋ฅผ ์›ํ•  ๋•Œ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ด ๋‚ด์žฅํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.

 

 

๐Ÿคท‍โ™‚๏ธ filter() ํ•จ์ˆ˜์˜ ์˜ˆ์ œ


๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฐ์—ด์ด ์žˆ์Šต๋‹ˆ๋‹ค.

const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฐ์—ด์—์„œ ์ง์ˆ˜์˜ ๊ฒฐ๊ณผ๊ฐ’๋งŒ ๋„์ถœํ•˜๊ณ  ์‹ถ์„ ๋•Œ filter() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const evenNumbers = numbers.filter(function (number) {
  return number % 2 === 0;
});

console.log(evenNumbers); 
//๊ฒฐ๊ณผ๊ฐ’ [2, 4, 6, 8]

 

์œ„์— ์ฝ”๋“œ์—์„œ ์ง์ˆ˜์— ๋งŒ์กฑํ•˜๋Š” ์š”์†Œ๋งŒ ์ถ”์ถœํ•ด์„œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. 

 

 

์ตœ์‹  ๋ฌธ๋ฒ• ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ๋” ๊ฐ„๊ฒฐํ•œ ์ฝ”๋“œ๋กœ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const evenNumbers = numbers.filter((number) => number % 2 === 0);

console.log(evenNumbers); 
//๊ฒฐ๊ณผ๊ฐ’ [2, 4, 6, 8]

 

ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ์ˆ˜์ •ํ•˜๊ณ  ์ฝ”๋“œ๋ฅผ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

๋ฐ˜๋Œ€๋กœ ํ™€์ˆ˜๊ฐ’๋งŒ ๋„์ถœํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋„ filter() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const evenNumbers = numbers.filter((number) => number % 2 !== 0);

console.log(evenNumbers); 
//๊ฒฐ๊ณผ๊ฐ’ [1, 3, 5, 7, 9]

 

ํ™”์‚ดํ‘œ ํ•จ์ˆ˜์™€ ํ•œ ์ค„๋กœ ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด์„œ ํ™€์ˆ˜์— ๋งŒ์กฑํ•˜๋Š” ์š”์†Œ๋งŒ ์ถ”์ถœํ•ด์„œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. 

 

๐Ÿคท‍โ™‚๏ธ filter() ํ•จ์ˆ˜์˜ ์˜ˆ์ œ 2


์ฃผ์–ด์ง„ ๋ฐฐ์—ด์—์„œ 5 ์ด์ƒ์˜ ์ˆซ์ž๋งŒ ์ถ”์ถœํ•˜๊ธฐ

const numbers = [1, 5, 10, 15, 20];
const greaterThanFive = numbers.filter(number => number > 5);

console.log(greaterThanFive); // [10, 15, 20]

 

filter() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ„๊ฒฐํ•œ ์ฝ”๋“œ๋กœ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ ๊ฐ’์„ ๋„์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ filter() ํ•จ์ˆ˜์˜ ์˜ˆ์ œ 3


์กฐ๊ธˆ ๋” ๋‚œ์ด๋„๋ฅผ ๋†’์—ฌ์„œ ๊ฐ์ฒด ๋ฐฐ์—ด์— age 18 ์ด์ƒ์ธ ๊ฐ์ฒด๋งŒ ์ถ”์ถœํ•˜๊ธฐ

const users = [
  { name: "Kim", age: 16 },
  { name: "Lee", age: 25 },
  { name: "Park", age: 30 },
  { name: "Choi", age: 14 },
  { name: "Jeon", age: 19 },
];

const adults = users.filter(user => user.age >= 18);

console.log(adults);
// ๊ฒฐ๊ณผ๊ฐ’ 
[
    {
        "name": "Lee",
        "age": 25
    },
    {
        "name": "Park",
        "age": 30
    },
    {
        "name": "Jeon",
        "age": 19
    }
]

 

๊ฐ์ฒด ๋ฐฐ์—ด์—์„œ age 18 ์ด์ƒ์ธ ๊ฐ์ฒด๋งŒ ์ฐพ์•„์„œ ์ƒˆ๋กœ์šด ๊ฐ์ฒด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๐Ÿคท‍โ™‚๏ธ ๋งˆ์ง€๋ง‰์œผ๋กœ


์œ„์— ์˜ˆ์ œ๋“ค์„ ํ†ตํ•ด์„œ filter() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์›ํ•˜๋Š” ๋ฐฐ์—ด๋กœ ํ•„ํ„ฐ๋งํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

filter() ํ•จ์ˆ˜๋ฅผ ์ž˜ ํ™œ์šฉํ•˜๋ฉด ๋ณต์žกํ•˜๊ณ  ์„ฑ๋Šฅ์— ์•ˆ ์ข‹์€ for๋ฌธ, ๋ฐ˜๋ณต๋ฌธ ์—†์ด๋„ ๊ฐ„๊ฒฐํ•˜๊ณ  ์›ํ•˜๋Š” ์กฐ๊ฑด์œผ๋กœ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๊ฐ’๋งŒ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์— ๋ฐฐ์—ด ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ์ž˜ ํ™œ์šฉํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๊ฐ„์†Œํ™”ํ•˜๊ณ  ์„ฑ๋Šฅ์ธก๋ฉด์—์„œ๋„ ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 


 

์žฌ๋ฐŒ๋Š” ์˜ค๋Š˜์˜ ๋ ๋ณ„ ์šด์„ธ ๋ณด๊ณ  ๊ฐ€์„ธ์š”! 

 

 

https://cometruedream.tistory.com/247

 

[React] Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผ className ์ปค์Šคํ…€

๐Ÿคท‍โ™‚๏ธ Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผํ”„๋กœ์ ํŠธ ์ง„ํ–‰์ค‘ ๋ฐฐ๋„ˆ ๋งํฌ์— URL ๊ธธ์ด๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์„œ 3์ค„ ํšจ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. React + Tailwind CSS ์…‹ํŒ…๋œ ํ”„๋กœ์ ํŠธ ์—ฌ์„œ CSS ํŒŒ์ผ & style ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/243

 

NestJS Lifecycle (์ƒ๋ช…์ฃผ๊ธฐ) ๊ฐœ๋…

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ Nest JS ๊ฐœ๋…?Nest JS๋Š” Node JS ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒ๋‹นํžˆ ์˜ค๋žซ๋™์•ˆ Express ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ ์••๋„์ ์ธ ์ 

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/242

 

๋ฆฌ์•กํŠธ Vite Proxy ํ™œ์šฉํ•œ CORS ์˜ค๋ฅ˜ ํ•ด๊ฒฐ

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋ก ํŠธ์—”๋“œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ต์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ๊ธ€์„ ๋ณด์‹œ๋ฉด ๋” ๋งŽ์€ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค^^ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ตhttps://comet

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/241

 

React ํด๋”๊ตฌ์กฐ FSD ๊ธฐ๋Šฅ ๋ถ„ํ™œ ์„ค๊ณ„ ์•„ํ‚คํ…์ฒ˜

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ ํด๋” ๊ตฌ์กฐ, ์„ค๊ณ„์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ƒ๋‹นํžˆ ์–ด๋ ต๋‹ค. ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์— React FSD ํด๋”๊ตฌ์กฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ค๊ณ„ํ•  ์˜ˆ์ •์ด๋ผ์„œ FSD ์•„ํ‚คํ…

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/244

 

์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋Š” Prisma ๋ช…๋ น์–ด ์ •๋ฆฌ

๐Ÿคท‍โ™‚๏ธ Prisma ๋ช…๋ น์–ด ๋ณธ๋ก ์— ์•ž์„œ Prisma๋ž€?Nest JS ํ”„๋ ˆ์ž„์›Œํฌ์™€ Prisma ORM์„ ํ™œ์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ Prisma๋Š” Node JS ๊ธฐ๋ฐ˜์— ํ”„๋ ˆ์ž„์›Œํฌ/๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ž˜๋˜๋ฉฐ Prisma + DB ์—ฐ๋™์œผ

cometruedream.tistory.com