๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ฐฐ์—ด์˜ ์›์†Œ ์‚ญ์ œํ•˜๊ธฐ ๋ณธ๋ฌธ

๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ฐฐ์—ด์˜ ์›์†Œ ์‚ญ์ œํ•˜๊ธฐ

Eun_zii 2024. 3. 4. 17:28

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- ๋ฐฐ์—ด์˜ ์›์†Œ ์‚ญ์ œํ•˜๊ธฐ

 

๐Ÿ’š ๋ฌธ์ œ์„ค๋ช…

  • ์ •์ˆ˜ ๋ฐฐ์—ด arr๊ณผ delete_list๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. arr์˜ ์›์†Œ ์ค‘ delete_list์˜ ์›์†Œ๋ฅผ ๋ชจ๋‘ ์‚ญ์ œํ•˜๊ณ  ๋‚จ์€ ์›์†Œ๋“ค์€ ๊ธฐ์กด์˜ arr์— ์žˆ๋˜ ์ˆœ์„œ๋ฅผ ์œ ์ง€ํ•œ ๋ฐฐ์—ด์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”.

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 1 ≤ arr์˜ ๊ธธ์ด ≤ 100
  • 1 ≤ arr์˜ ์›์†Œ ≤ 1,000
  • arr์˜ ์›์†Œ๋Š” ๋ชจ๋‘ ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
  • 1 ≤ delete_list์˜ ๊ธธ์ด ≤ 100
  • 1 ≤ delete_list์˜ ์›์†Œ ≤ 1,000
  • delete_list์˜ ์›์†Œ๋Š” ๋ชจ๋‘ ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

 

๐Ÿ’š ํ’€์ด

function solution(arr, delete_list) {
    return arr.filter(n => !delete_list.includes(n))
}

 

โœ… 

๋ฐฐ์—ด์—์„œ ๋ฐฐ์—ด์„ ๋นผ๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ณ ,

filter( ) ๋ฉ”์„œ๋“œ( ์ฃผ์–ด์ง„ ํ•จ์ˆ˜๋ฅผ ํ†ต๊ณผํ•˜๋Š” ๋ชจ๋“  ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๋Š” ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. )๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

 

delete_list์— ํฌํ•จ๋˜์ง€ ์•Š๋Š” ์š”์†Œ๋“ค๋งŒ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.  

!delete_list.includes(n)๋Š” delete_list์— n์ด ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์„ ๋•Œ true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ arr์—์„œ delete_list์— ์žˆ๋Š” ์š”์†Œ๋“ค์„ ์ œ์™ธํ•œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ return ํ•œ๋‹ค.

728x90