[프로그래머스][자바스크립트][Level1] 모의고사
/** * 모의고사 * 완전탐색 */ function solution(answers) { const supoja = [0, 0, 0]; const supojaPattern = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]; answers.forEach((val, idx) => { for (let i = 0; i < supojaPattern.length; i++) { if (val === supojaPattern[i][idx%supojaPattern[i].length]) supoja[i]++; } }); const max = Math.max(...supoja); return supoja.reduce((rst, matc..
2022. 1. 3.
[프로그래머스][자바스크립트][Level2] 타겟 넘버
https://programmers.co.kr/learn/courses/30/lessons/43165 function solution(numbers, target) { var answer = {number: 0}; f(numbers, 0, 0, answer, target, "+"); f(numbers, 0, 0, answer, target, "-"); return answer.number; } function f(numbers, idx, result, answer, target, calc) { if (calc === "+") { result += numbers[idx]; } else if (calc === "-") { result -= numbers[idx]; } if (numbers.length - 1..
2021. 7. 20.