๐Ÿ’ก Level 1 | ์„œ์šธ์—์„œ ๊น€์„œ๋ฐฉ ์ฐพ๊ธฐ (JavaScript)

rimmzยท2022๋…„ 7์›” 1์ผ
0

programmers

๋ชฉ๋ก ๋ณด๊ธฐ
10/15
post-thumbnail

๐Ÿ“Œ ๋ฌธ์ œ

  • Stringํ˜• ๋ฐฐ์—ด seoul์˜ element์ค‘ "Kim"์˜ ์œ„์น˜ x๋ฅผ ์ฐพ์•„, "๊น€์„œ๋ฐฉ์€ x์— ์žˆ๋‹ค"๋Š” String์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. seoul์— "Kim"์€ ์˜ค์ง ํ•œ ๋ฒˆ๋งŒ ๋‚˜ํƒ€๋‚˜๋ฉฐ ์ž˜๋ชป๋œ ๊ฐ’์ด ์ž…๋ ฅ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†์Šต๋‹ˆ๋‹ค.

https://programmers.co.kr/learn/courses/30/lessons/12919

๐Ÿ“ ๋ฌธ์ œ ํ’€์ด

function solution(seoul) {
  const num = seoul.indexOf("Kim");
  return `๊น€์„œ๋ฐฉ์€ ${num}์— ์žˆ๋‹ค`;
}
  • indexOf๋กœ 'Kim' ์œ„์น˜๋ฅผ ์ฐพ์•„์„œ ๋ฐ˜ํ™˜

๐Ÿ’ฌ ์ •๋ฆฌ

  • arr.indexOf(searchElement[, fromIndex]) ๋ฐฐ์—ด ์•ˆ์—์„œ ์ฐพ์œผ๋ ค๋Š” ๊ฐ’(searchElement)๊ณผ ์ •ํ™•ํ•˜๊ฒŒ ์ผ์น˜(===)ํ•˜๋Š” '์ฒซ๋ฒˆ์งธ' element์˜ index ๋ฐ˜ํ™˜
  • ย searchElement ์ฐพ์œผ๋ ค๋Š” ๊ฐ’
  • ย fromIndex ๊ฒ€์ƒ‰์„ ์‹œ์ž‘ํ•  index ์œ„์น˜ (์ƒ๋žต ์‹œ ๋ถ€ํ„ฐ ๊ฒ€์ƒ‰)
profile
#์˜์š•๋„˜์น˜๋Š”#๐Ÿ’ป#โœจ#FE#๐Ÿ’ช๐Ÿป

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