걍가영 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) : []);
}