본문 바로가기
Today I learned!/오늘 하루 배운 것, 기억할 것

220628

by sweesweet 2022. 6. 28.

Array.prototype.every()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every

 

Array.prototype.every() - JavaScript | MDN

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

developer.mozilla.org

오늘 코플릿에서 나온문제(2의 배열이 1의 부분집합인가=> 맞다면 true 아니라면 false)

에서 시간혼잡도를 고려하지않고 문제를 푼다고 할 때 every를 통해서 false와 true를 간단하게 알아낼 수 있음

 

다만 시간혼잡도일때는 함수를 새로만들어서 그 함수를 적용하면서 for문을 돌리는 방법이 더빠르다

 

돔일때는 함수안에 함수 잘만넣으면서 코테할때는 왜 문제 함수 1개여야 하는 고정관념이 사라지지않는지 모르겠다..