본문 바로가기

전체보기

(62)
TapeEquilibrium_codility 문제 A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])| In other words, it is the absolute dif..
PermMissingElem_codility 문제 An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: function solution(A); that, given an array A, returns the value of the missing element. For example, given array A such that: A[0] = 2, A[1] = 3, A[2] = 1, A[3] = 5 the funct..
FrogJmp_codility 문제 A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: function solution(X, Y, D); that, given three integers X, Y and D, returns the m..
OddOccurrencesInArray_Codility 문제 A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2 have value 9, the elements a..
CyclicRotation_Codility 문제 An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that is, each eleme..
How to avoid repeating addEventListener? 3개의 버튼이 존재하고 버튼을 클릭했을 때 각 버튼은 내용이 다른 모달이 열릴 수 있도록 코드를 작성하려고했다. 그런데 addEventListener가 한번 정의되지 않고 여러 번 정의가 되서 버튼을 클릭했을 때 여러번 작동되는 문제가 발생했다. 문제를 분석해 보니 이벤트 리스너는 이벤트에 대해 등록될 때마다 새로운 객체로 생성됐다. 즉, n번 등록된 리스너의 래퍼런스는 모두 다 달라 중복 처리가 안되고 있었다. 시도1 addEventListener 중복을 피하는 핵심은 추가하기 전에 removeEventListener에 의해 추가된 처리 기능을 제거하는 것이다. const $btn = document.getElementById('btn'); function clickHandler() { console...
Function.prototype.bind() 함수 메소드 call, apply, bind는 첫번째 매개 변수로 this 값을 명시적으로 지정할 수 있다는 공통점이 있다. 단, bind는 call, apply와 달리 새로운 함수를 반환한다는 특징이 있다. 변수 할당 후 재호출, setTimeout 적용하여 사용할 수 있다. 사라진 'this' let user = { firstName: "Irene", sayHi() { alert(`Hello ${this.firstName}`); } } setTimeout(user.sayHi, 1000); // Hello undefined setTimeout 메서드는 인수로 전달받은 함수를 호출할 때 this에 window를 할당한다. 따라서 위 예시의 this.firstName은 window.firstName이 되는..
Jquery UI draggable creates a whitespace 팝업을 오른쪽으로 드래그하면 흰색 공간이 생성되는 버그를 발견했다. 원인을 분석해보니 팝업이 overflow가 되기때문에 CSS issue 라는 것으로 이해했다.