https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.
설명:
아주 간단합니다. 문자열에서 처음과 마지막 글자를 제거하는 함수를 만드세요. 원본 문자열인 매개변수 하나가 주어집니다. 두 단어 미만인 문자열에 대해 걱정할 필요가 없습니다.
풀이
slice로 문자열을 1부터 마지막 전까지 잘랐다.
코드
function removeChar(str){
return str.slice(1, str.length - 1);
};
참고
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Array.prototype.slice() - JavaScript | MDN
slice() 메서드는 어떤 배열의 begin 부터 end 까지(end 미포함)에 대한 얕은 복사본을 새로운 배열 객체로 반환합니다. 원본 배열은 바뀌지 않습니다.
developer.mozilla.org
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Grasshopper - Summation (8 kyu) / JavaScript (0) | 2022.12.08 |
---|---|
[Codewars] String repeat (8 kyu) / JavaScript (0) | 2022.12.07 |
[Codewars] Find the smallest integer in the array (8 kyu) / JavaScript (0) | 2022.12.05 |
[Codewars] Counting sheep... (8 kyu) / JavaScript (0) | 2022.12.03 |
[Codewars] Sum of two lowest positive integers (7 kyu) / JavaScript (0) | 2022.12.02 |
댓글