๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์•Œ๊ณ ๋ฆฌ์ฆ˜

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ : ๋ฌธ์ž์—ด์„ ์ •์ˆ˜๋กœ ๋ฐ”๊พธ๊ธฐ

by _ํ† ๋งคํ†  2022. 11. 7.
728x90

๐Ÿ–ฑ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ : ์„œ์šธ์—์„œ ๊น€์„œ๋ฐฉ ์ฐพ๊ธฐ ๐Ÿ–ฑ


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

์ œํ•œ ์‚ฌํ•ญ : seoul์€ ๊ธธ์ด 1 ์ด์ƒ, 1000 ์ดํ•˜์ธ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค.
seoul์˜ ์›์†Œ๋Š” ๊ธธ์ด 1 ์ด์ƒ, 20 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
"Kim"์€ ๋ฐ˜๋“œ์‹œ seoul ์•ˆ์— ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

function solution(seoul) {
    let answer = seoul.indexOf("Kim");
    return "๊น€์„œ๋ฐฉ์€ " + answer+ "์— ์žˆ๋‹ค";
}

์ธ๋ฑ์Šค ์˜ค๋ธŒ ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์„œ์šธ์—์„œ KIM์„ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ํ›„ ๊ทธ ๊ฐ’์„ ๋ฆฌํ„ด์„ ํ†ตํ•ด ๋ฌธ์ž์—ด๊ณผ ํ•จ๊ป˜ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.


728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css