Algorithm/codewars

Are they the "same"? 답안

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

문제)

www.codewars.com/kata/550498447451fbbd7600041c/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 comp(array1, array2){
  if (array1 === null || array2 === null) {
    return false;
  }
  
  var isSame = true;
  for (var elem1 of array1) {
    var index = array2.indexOf(elem1*elem1);
    
    if (index === -1) {
      isSame = false;
      break;
    } else {
      array2.splice(index, 1);
    }
  }
  return isSame;
}

 

테스트 결과)

 

마음에 드는 다른 사람 소스)

728x90
반응형

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

Where my anagrams at? 답안  (0) 2021.03.24
Equal Sides Of An Array 답안  (0) 2021.03.24
Counting Duplicates 답안  (0) 2021.03.24
Valid Braces 답안  (0) 2021.03.24
Calculating with Functions 답안  (0) 2021.03.24