1. 알고리즘
1- 1) 프로그래머스 옹알이(2) 문제
규칙과 조건이 있는 단어 찾기는 정규표현식 적극 활용할 것
// 기존 답안
function solution(babbling) {
const can = ['aya','ye','woo','ma'];
let count = 0;
for (let word of babbling) {
let lastSound = '';
let isValid = true;
while (word.length > 0 && isValid) {
let found = false;
for (let sound of can) {
if (word.startsWith(sound) && sound !== lastSound) {
word = word.slice(sound.length);
lastSound = sound;
found = true;
break;
}
}
if (!found) {
isValid = false;
}
}
if (isValid && word.length === 0) {
count++;
}
}
return count;
}
위 코드를 아래로 리팩토링이 가능하다.
//리팩토링
function solution(babbling) {
const can = ['aya', 'ye', 'woo', 'ma'];
const regex = new RegExp(`^(${can.join('|')})+$`); // (aya|ye|woo|ma), + : 앞의 패턴(허용된 발음)이 1번 이상 반복
const repeatRegex = /(aya|ye|woo|ma)\1+/;
return babbling.filter(word =>
regex.test(word) && !repeatRegex.test(word)
).length;
}
1- 2) 프로그래머스 실패율 문제
단축평가 리마인드
// 기존답안
function solution(N, stages) {
let result = []
let denominator = stages.length
for( let i = 1; i <= N;i++){
let person = stages.filter(e => e === i).length
result.push({ stage: i, rate: person / denominator })
denominator-=person
}
return result.sort((a,b) => {
if(a.rate !== b.rate) return b.rate - a.rate
else return a.stage - b.stage
}).map(e => e.stage)
}
// 리팩토링
function solution(N, stages) {
let result = []
let denominator = stages.length
for( let i = 1; i <= N;i++){
let person = stages.filter(e => e === i).length
result.push({ stage: i, rate: person / denominator })
denominator-=person
}
// 위조건처럼 b.rate, a.rate 두개가 같으면 0이 되므로 자동적으로 falsy 한 값이 되어
// 단축평가에서 두번째 값을 평가하게 됨
return result.sort((a, b) => b.rate - a.rate || a.stage - b.stage).map(e => e.stage)
}
2. CSS
2-1 ) box-sizing: border-box;
box model 사이즈 계산시 padding border 를 포함한 width height 가 되도록 하는 속성
이걸 몰라서 cal() 을 써서 padding border 을 빼주고 난리를 쳤었다..
2-2 ) margin , padding 도 border-radius 처럼 4개의 속성까지 줄 수 있다
단 border-radius 와는 순서가 조금 다르다 (상 -> 우 -> 하 -> 좌)
2-3) box-shadow , text-shadow 차이를 알 수 있었다
box-shadow는 spread 매개변수가 있지만, text-shadow에는 없다
box-shadow는 inset 키워드를 사용해 내부 그림자를 만들 수 있지만, text-shadow는 불가능
3. Next js
Pages Router vs App Router 차이점 및 장단점 파악
https://daunje0.tistory.com/146
[Next.js] Pages Router vs App Router 비교
1. 디렉토리 구조 Pages Router: /pages App Router: /app 2. 라우팅 방식 Pages Router: 파일 기반 App Router: 폴더 기반 3. 주요 파일 Pages Router:/pages ├── index.js ├── abou
daunje0.tistory.com
4. PostgreSql
기존 mysql AUTO_INCREMENT 와 같은 개념인 serial 타입에 대해 알게 됨
https://daunje0.tistory.com/145
[PostgreSQL] 데이터 타입 SERIAL
SERIAL은 PostgreSQL에서 자주 사용되는 특별한 데이터 타입입니다. 자동 증가: SERIAL 컬럼은 자동으로 증가하는 정수 값을 생성합니다.기본키로 사용: 주로 테이블의 기본키(Primary Key)로 사용됩니다.
daunje0.tistory.com
'TIL(Today I Learned) > 2024.09' 카테고리의 다른 글
[TIL] 9.30 (0) | 2024.09.30 |
---|---|
[TIL] 9.29 (0) | 2024.09.30 |
[TIL] 9.28 (0) | 2024.09.29 |
[TIL] 9.26 (0) | 2024.09.26 |