https://school.programmers.co.kr/learn/courses/30/lessons/42587?language=javascript 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

function solution(priorities, location) {
    // priorities 중요도
    // location 내가 인쇄를 요청한 문서가 현재 대기목록의 어떤 위치에 있는지 알려주는 변수
    // answer 내가 요청한 문서가 몇 번째로 인쇄되는지 return
    
    let printed = 0;
    priorities = priorities.map((p,index) => {
        if(index === location) return {prio: p, target: true};
        return {prio: p, target: false};
    });
        
    while(true) {
        const arr = priorities.map(p => {
            return p.prio;
        });
        let max = Math.max(...arr);
        
        if(priorities[0]['prio'] !== max) {
            let prio = priorities.shift();
            priorities.push(prio);
        } else {
            if(priorities[0]['target'] === true) {
                return ++printed;
            }
            priorities.shift();
            printed++;
        }
    }
}
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/64065

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

function solution(s) {
    var answer = [];
    const set = new Set();
    s = s.split("");
    s.shift();
    s.splice(s.length-1, 1);
    s = s.join("");
    s = s.replaceAll('},', " ");
    s = s.replaceAll('{', " ");
    s = s.replaceAll('}', " ");
    s = s.split(" ");
    s = s.filter((v) => v !== '');
    s.sort(function(a,b) {
       return a.length - b.length; 
    });
    
    s.forEach((d) => {
        d = d.split(",");
        d.forEach((data) => {
            set.add(Number(data));
        });
    })
    
    return Array.from(set);
}
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/120875

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

function solution(dots) {
    for(let i = 0 ; i < 3  ; i++){
        for(let  j = 0 ; j < 3 - i; j++) {
            const tmp1 = [dots[i], dots[i+j+1]];
            const tmp2 = dots.filter((d) => {
                return ![dots[i].join(""),dots[i+j+1].join("")].includes(d.join(""));
            });
            
            const inclination1 = Math.abs((tmp1[0][0] - tmp1[1][0])/(tmp1[0][1] - tmp1[1][1]));
            const inclination2 = Math.abs((tmp2[0][0] - tmp2[1][0])/(tmp2[0][1] - tmp2[1][1]));
            
            if(inclination1 === inclination2) {
                return 1;
            }
        }
    }
    
    return 0;
}
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/120840

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

function factorial(n) {
    let result = 1;
    for(let i = 2 ; i <= n ; i++) {
        result *= i;
    }
    return result;
}

function solution(balls, share) {
    const n_ = factorial(balls); // n!
    const m_ = factorial(share); // m!
    const n_m = factorial(balls-share); // (n-m)!
    
    return Math.round((n_)/(n_m * m_));   
}
728x90

+ Recent posts