프로그래머스(코딩 테스트)/Lv.0
왼쪽 오른쪽
걍가영
2024. 10. 19. 22:11
// javascript
const solution = (str_list) => {
const lIndex = str_list.indexOf('l');
const rIndex = str_list.indexOf('r');
return (lIndex !== -1 && (rIndex === -1 || lIndex < rIndex))
? str_list.slice(0, lIndex)
: (rIndex !== -1 ? str_list.slice(rIndex + 1) : []);
}
// typescript
const solution = (str_list: string[]): string[] => {
const lIndex = str_list.indexOf('l');
const rIndex = str_list.indexOf('r');
return (lIndex !== -1 && (rIndex === -1 || lIndex < rIndex))
? str_list.slice(0, lIndex)
: (rIndex !== -1 ? str_list.slice(rIndex + 1) : []);
}