๐Ÿšผ[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ฐฐ์—ด์˜ ์œ ์‚ฌ๋„

Chobbyยท2022๋…„ 10์›” 12์ผ
1

Programmers

๋ชฉ๋ก ๋ณด๊ธฐ
84/349

๐Ÿงก๋ฌธ์ œ ์„ค๋ช…

๋‘ ๋ฐฐ์—ด์ด ์–ผ๋งˆ๋‚˜ ์œ ์‚ฌํ•œ์ง€ ํ™•์ธํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐฐ์—ด s1๊ณผ s2๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ™์€ ์›์†Œ์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.


๐Ÿ’›์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค s1, s2์˜ ๊ธธ์ด โ‰ค 100
  • 1 โ‰ค s1, s2์˜ ์›์†Œ์˜ ๊ธธ์ด โ‰ค 10
  • s1๊ณผ s2์˜ ์›์†Œ๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค
  • s1๊ณผ s2๋Š” ๊ฐ๊ฐ ์ค‘๋ณต๋œ ์›์†Œ๋ฅผ ๊ฐ–์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๐Ÿ’š์ž…์ถœ๋ ฅ ์˜ˆ

s1s2result
["a", "b", "c"]["com", "b", "d", "p", "c"]2
["n", "omg"]["m", "dot"]0

๐Ÿ’™์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • "b"์™€ "c"๊ฐ€ ๊ฐ™์œผ๋ฏ€๋กœ 2๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • ๊ฐ™์€ ์›์†Œ๊ฐ€ ์—†์œผ๋ฏ€๋กœ 0์„ returnํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’œ๋‚˜์˜ ํ’€์ด

const solution = (s1, s2) => s1.filter((a,i) => s2.includes(a)).length
profile
๋‚ด ์ง€์‹์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋‹ดํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€