kakasoo

[node.js] 프린터 ( 프로그래머스 레벨2 ) 본문

프로그래밍/알고리즘 풀이

[node.js] 프린터 ( 프로그래머스 레벨2 )

카카수(kakasoo) 2021. 6. 28. 15:48
반응형
// 프로그래머스 레벨2 프린터를 풀었습니다.
const 더큰게있니 = (얘, 다른애들) => {
  for (let i = 0; i < 다른애들.length; i++) {
    if (다른애들[i].prio > 얘.prio) return true;
  }
  return false;
};

function solution(priorities, location) {
  let index = [];
  priorities.map((el, i) => {
    index.push({ idx: i, prio: el });
  });
  console.log(index);

  let count = 0;
  while (index.length !== 0) {
    let temp = index.shift();
    if (더큰게있니(temp, index)) {
      index.push(temp);
    } else {
      count++;
      if (temp.idx === location) return count;
    }
  }
}

예전에 풀어서 함수 명을 왜 저렇게 했는지 기억이 안난다.

반응형