isSubsetOf

Written on July 20, 2019

문제

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

풀이

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

👩🏻‍💻 배우는 것을 즐기는 프론트엔드 개발자 입니다
부족한 블로그에 방문해 주셔서 감사합니다 🙇🏻‍♀️

in the process of becoming the best version of myself