알고리즘 공부를 위한 셋팅

programmers.co.kr

by Daehyun Im

HTML

<div id="result"></div>

JavaScript

function solution(clothes) {
		clothes.sort();
    
    let kindOfClothes = [];
    let list = [];
    for(let i in clothes) {
    	if(!kindOfClothes.includes(clothes[i][1])) {
      	kindOfClothes.push(clothes[i][1]);
      }
      list.push(clothes[i][1]);
    }

    let result = kindOfClothes.reduce( (sum, current) => {
      return sum * (list.filter(x => x==current).length + 1);
    } , 1) - 1;

    var answer = result;
    return answer;
}

var input = [
  ['yellow_hat', 'headgear'],
  ['blue_sunglasses', 'eyewear'],
  ['green_turban', 'headgear']
];

var result = solution(input);

console.log(result);
document.getElementById('result').innerHTML = result;