๋ฌธ์ œ

๋ฌธ์ž์—ด s๋ฅผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”.

์˜ˆ๋ฅผ๋“ค์–ด str์ด "1234"์ด๋ฉด 1234๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , "-1234"์ด๋ฉด -1234๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
str์€ ๋ถ€ํ˜ธ(+,-)์™€ ์ˆซ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ณ , ์ž˜๋ชป๋œ ๊ฐ’์ด ์ž…๋ ฅ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†์Šต๋‹ˆ๋‹ค.

 

์‚ฌ์šฉํ•œ ํ•จ์ˆ˜ 

Number() : ๊ด„ํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์ˆซ์ž๋กœ ๋ฐ˜ํ™˜

 

ํ•ด๊ฒฐ

function solution(s) {
    var answer = 0;
    answer = Number(s)
    return answer;
}

 

ํ•ด๊ฒฐ (ํŒ€์› ์ฐธ๊ณ )

function solution(s) {
	var answer = parseInt(s);
    return answer;
}

์‚ฌ์šฉํ•œ ํ•จ์ˆ˜ :

perseIns() : ๊ด„ํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜

+ Recent posts