programmer: Make a burger

2023. 11. 28. 23:19카테고리 없음

function solution(ingredient) {
    let answer = 0;
    const stack = [];

    for (let i of ingredient) {
        stack.push(i);

        if (stack.slice(-4).join("") == "1231") {
            stack.splice(-4);
            answer++;
        }
    }
    return answer;
}

 

Reference material

for ... of

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/for...of