Algorithm/codewars

Where my anagrams at? 답안

Bonita SY 2021. 3. 24. 20:45
728x90
반응형

문제)

www.codewars.com/kata/523a86aa4230ebb5420001e1/train/javascript

 

Codewars: Achieve mastery through challenge

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com

 

내가 푼 답)

function anagrams(word, words) {
  const result = [];
  const target = word.split('').sort().join('');
  
  for (var elem of words) {
    const tmp_elem = elem.split('').sort().join('');
    if (target === tmp_elem) {
      result.push(elem);
    }
  }
  
  return result;
}

 

테스트 결과)

 

마음에 드는 남이 푼 소스)

728x90
반응형

'Algorithm > codewars' 카테고리의 다른 글

Greed is Good 답안  (0) 2021.03.24
Moving Zeros To The End 답안  (0) 2021.03.24
Equal Sides Of An Array 답안  (0) 2021.03.24
Are they the "same"? 답안  (0) 2021.03.24
Counting Duplicates 답안  (0) 2021.03.24