상세 컨텐츠

본문 제목

isSubsetOf (Array method) - Javascript

카테고리 없음

by 쌩우 2019. 6. 7. 23:15

본문

isSubsetOf

  • Array Method의 일종으로, 어떤 한 배열의 모든 원소에 대하여, 다른 배열이 그것을 모두 포함할 때에 true 값을 return하도록 하는 method이다.
 //Make an array method that can return whether or not a context array is a
 // subset of an input array.  To simplify the problem, you can assume that both
 // arrays will contain only strings.
 // var a = ['commit','push']
 // a.isSubsetOf(['commit','rebase','push','blame']) // true
 // NOTE: You should disregard duplicates in the set.
 // var b = ['merge','reset','reset']
 // b.isSubsetOf(['reset','merge','add','commit']) // true 

 Array.prototype.isSubsetOf = function(array){
  for(let i = 0; i < this.length; i++) {
      if(!array.includes(this[i])) {
        return false;
    }
  }
  return true
};

댓글 영역