πŸ“œ λͺ©μ°¨

μ•Œκ³ λ¦¬μ¦˜

폰켓λͺ¬

μ•Œκ³ λ¦¬μ¦˜ ν…ŒμŠ€νŠΈ

두 λ°°μ—΄μ˜ 차이

팬그램

κ±°μŠ€λ¦„λˆ

λ’€μ£½λ°•μ£½

NestJS

Many-To-Many

Login Process

JWT

μ•Œκ³ λ¦¬μ¦˜

πŸ“Œ set()

const set = new Set()
console.log(set) // Set(0) {}, 인수λ₯Ό μ „λ‹¬ν•˜μ§€ μ•ŠμœΌλ©΄ 빈 Set 객체가 생성됨

// μ€‘λ³΅λœ 값은 Set 객체에 μš”μ†Œλ‘œ μ €μž₯λ˜μ§€ μ•ŠμŒ
const set1 = new Set([1,2,3,3])
console.log(set1) //Set(3) {1,2,3}

const set2 = new Set("hello")
console.log(set2) //Set(4){'h', 'e', 'l', 'o'}

// λ°°μ—΄μ—μ„œ μ€‘λ³΅λœ μš”μ†Œλ₯Ό 제거
const uniq = array => array.filter(( v, i, self ) => self.indexOf(v) ==i)
// ν˜Ήμ€?
const uniq = array > [...new Set(array)]
console.log(uniq([2,1,2,3,4,3,4]))  // [2,1,3,4]
// μš”μ†Œ 개수 확인 (.size μ‚¬μš©, λ°°μ—΄μ˜ 개수λ₯Ό ν™•μΈν•˜λŠ” .length()와 ν—·κ°ˆλ¦¬μ§€ 말기!) 
const {size} = new Set([4,3,4,3,8,8,4,6])
console.log(size) // 4

const set3 = new Set([0,4,0,8])
set3.size === 3 // true

// μš”μ†Œ μΆ”κ°€ (.add() μ‚¬μš©, 배열을 μΆ”κ°€ν•˜λŠ” .push()와 ν—·κ°ˆλ¦¬μ§€ 말기!) 
const set4 = new Set()
set4.add(3)
console.log(set4) // Set(1){3}

// 연속 좔가도 κ°€λŠ₯
set4.add(4).add(8).add(7)
console.log(set4) // Set(1){3,4,8,7}

// μš”μ†Œ 쑴재 μ—¬λΆ€ 확인
console.log(set4.has(3))
console.log(set4.has(1)) //false

// μš”μ†Œ μ‚­μ œ , boolean κ°’ λ°˜ν™˜ (true or false)(.delete() μ‚¬μš©, .pop() μ΄λž‘ ν—·κ°ˆλ¦¬μ§€ 말자~) 
set4.delete(3) // μ‚­μ œ 성곡, true λ°˜ν™˜
set4.delete(3) // 이미 μœ„μ—μ„œ μ‚­μ œκ°€ 된 μš”μ†Œμ΄κΈ° λ•Œλ¬Έμ— μ‚­μ œκ°€ λΆˆκ°€λŠ₯ν•˜μ—¬ falseλ₯Ό λ°˜ν™˜ν•œλ‹€.

// Set 객체의 λͺ¨λ“  μš”μ†Œ 일괄 μ‚­μ œ
console.log(set4) // Set(3) {4,8,7}
set4.clear()
console.log(set4) // Set(0) {}

πŸ“Œ forEach()

const arr = [1, 2, 3, 4, 5];

// forEach() μ‚¬μš©
arr.forEach((element) => {
  console.log(element);
});

πŸ’­ 폰켓λͺ¬

// 문제 : <https://programmers.co.kr/learn/courses/30/lessons/1845> (ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€)

function solution(nums) {
    const answer = []
    
    for (let i = 0 ; i < nums.length; i++){
        if ( (nums.length / 2) !== answer.length &&
            answer.includes( nums[i] ) === false ) {
            answer.push( nums[i] );
        }
        if( (nums.length / 2) === answer.length ){
            break;
        }
    }
    return answer.length
}

//set() μ΄μš©ν•΄μ„œ 쀑볡체크
// length => size
// push => add둜 λ³€κ²½
function solution(nums) {
    const answer = new Set([])
    
    for (let i = 0 ; i < nums.length; i++){
        if ( (nums.length / 2) !== answer.size ) {
            answer.add( nums[i] );
        }
        else { break }
        }
    return answer.size
}

// set(), forEach() ꡬ문 μ‚¬μš©ν•œ 풀이 
function solution(nums) {
    const answer = new Set([])
    
    nums.forEach( monster => {
        if( nums.length / 2 > answer.size){
            answer.add(monster) 
        }
    })
    return answer.size
}

// λ¦¬νŒ©ν† λ§
function solution(nums) {
    // μ΅œλŒ€ν•œ 넣을 수 μžˆλŠ” 폰켓λͺ¬μ˜ μ’…λ₯˜
    const answer = new Set(nums).size
    // μ΅œλŒ€ν•œ 넣을 수 μžˆλŠ” 폰켓λͺ¬μ˜ 갯수
    const limit = nums.length / 2
    
    if (limit >= answer){
        return answer
    }
    return limit
}

μ•Œκ³ λ¦¬μ¦˜ ν…ŒμŠ€νŠΈ πŸ₯²πŸ₯²