๐Ÿ“œ ๋ชฉ์ฐจ

์•Œ๊ณ ๋ฆฌ์ฆ˜

ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ

NestJS

ELK Stack - ElasticSearch / Logstash / Kibana

์•Œ๊ณ ๋ฆฌ์ฆ˜

๐Ÿ“Œ for-in ๊ตฌ๋ฌธ, Object.entries()


const obj = { name : "์ดํƒœ๋ฏผ", age: 22}
const array = **Object.entries**(obj) // [ ['name', '์ดํƒœ๋ฏผ'], ['age',22] ]

array[0][0] // 'name' (ํ‚ค ๊ฐ’)
array[0][1] // '์ดํƒœ๋ฏผ' (value ๊ฐ’)

for (let key in obj) {
  console.log (`${key} is ${obj[key]}`)
}

// 'name is ์ดํƒœ๋ฏผ'
// 'age is 22' 

๐Ÿ’ญ ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ

// ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค <https://programmers.co.kr/learn/courses/30/lessons/67256>

const leftNumbers = [ 1,4,7 ]      // ์™ผ์ชฝ ํ‚คํŒจ๋“œ์— ํ•ด๋‹นํ•˜๋Š” ์ˆซ์ž
const rightNumbers = [ 3,6,9 ]     // ์˜ค๋ฅธ์ชฝ ํ‚คํŒจ๋“œ์— ํ•ด๋‹นํ•˜๋Š” ์ˆซ์ž

function solution(numbers, hand) {
    let answer= ""
    
    // ํ˜„์žฌ ๋‘ ์—„์ง€ ์†๊ฐ€๋ฝ์ด ์–ด๋–ค ์œ„์น˜์— ์žˆ๋Š”์ง€
    const current ={
        left : 10 ,
        right : 12
    }
    for (let i = 0; i< numbers.length; i++){
        // ๋ˆ„๋ฅผ ๋ฒˆํ˜ธ๊ฐ€ ์™ผ์ชฝ ํ‚คํŒจ๋“œ์— ํ•ด๋‹น๋œ๋‹ค๋ฉด(์™ผ์ชฝ ์†๊ฐ€๋ฝ์œผ๋กœ ๋ˆ„๋ฅธ๋‹ค๋ฉด)
        if( leftNumbers.includes(numbers[i]) ){
            answer += "L"
            current["left"] = numbers[i] // ์™ผ์ชฝ ์†๊ฐ€๋ฝ์œผ๋กœ ์œ„์น˜ ๋ณ€๊ฒฝ
            
        // ๋ˆ„๋ฅผ ๋ฒˆํ˜ธ๊ฐ€ ์˜ค๋ฅธ์ชฝ ํ‚คํŒจ๋“œ์— ํ•ด๋‹น๋œ๋‹ค๋ฉด(์˜ค๋ฅธ์ชฝ ์†๊ฐ€๋ฝ์œผ๋กœ ๋ˆ„๋ฅธ๋‹ค๋ฉด)
        } else if ( rightNumbers.includes(numbers[i])){
            answer+="R"
            current["right"]=numbers[i] // ์˜ค๋ฅธ์ชฝ ์†๊ฐ€๋ฝ์œผ๋กœ ์œ„์น˜ ๋ณ€๊ฒฝ
        
        // ๊ฐ€์šด๋ฐ ํ‚คํŒจ๋“œ์— ํ•ด๋‹นํ•  ๊ฒฝ์šฐ
        } else { 
            const locationObj = { ...current } // ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ ์†๊ฐ€๋ฝ์˜ ์œ„์น˜ ๊ฑฐ๋ฆฌ๋ฅผ ์ €์žฅ
            
            for( let hand in locationObj ){
                // 0์„ ๋ˆŒ๋ €์„ ๋•Œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ = 0์€ 11 ์œ„์น˜ ๊ฐ’์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค
                numbers[i] = numbers[i] === 0 ? 11 : numbers[i]
                
                // ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ์—„์ง€ ์†๊ฐ€๋ฝ์œผ๋กœ๋ถ€ํ„ฐ ๊ฑฐ๋ฆฌ๊ฐ’์„ ๊ตฌํ•œ๋‹ค
                let location = Math.abs( numbers[i] - locationObj[hand] )
                
                // ๊ฑฐ๋ฆฌ ์ฐจ์ด๊ฐ€ 3์นธ ์ด์ƒ์ผ ๋•Œ๋Š” ์œ„์•„๋ž˜๋กœ ์ด๋™ ๊ฐ€๋Šฅ
                if(location >= 3){
                    location = Math.trunc(location / 3 + location % 3)
                }
                locationObj[ hand ] = location
            } 
            // ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ์†๊ฐ€๋ฝ ์œ„์น˜๊ฐ€ ์„œ๋กœ ๋™์ผํ•  ๊ฒฝ์šฐ
            // ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์†(๋งค๊ฐœ๋ณ€์ˆ˜ hand)์œผ๋กœ ๋ˆ„๋ฅธ๋‹ค
            if( locationObj["left"]===locationObj["right"] ){
                answer += hand === "left" ? "L" : "R"
                current [ hand ] = numbers[i]
            } else {
                if( locationObj["left"] >locationObj["right"] ){
                    // ์˜ค๋ฅธ์†์ด ๋” ๊ฐ€๊นŒ์šด ๊ฒฝ์šฐ
                    answer += "R"
                    current["right"] = numbers[i]
                } else {
                    // ์™ผ์†์ด ๋” ๊ฐ€๊นŒ์šด ๊ฒฝ์šฐ
                    answer += "L"
                    current["left"] = numbers[i]
                }
            }
        }
    }
    return answer
}

// reduce(), Object.entries(), ๋น„๊ตฌ์กฐํ• ๋‹น์„ ์‚ฌ์šฉํ•œ ํ’€์ด 
const [ leftNumbers,rightNumbers ] =[ [ 1,4,7 ], [ 3,6,9 ] ] 

function solution(numbers, hand) {
    // ํ˜„์žฌ ๋‘ ์—„์ง€ ์†๊ฐ€๋ฝ์ด ์–ด๋–ค ์œ„์น˜์— ์žˆ๋Š”์ง€
    const current ={
        left : 10 ,
        right : 12
    }
    return numbers.reduce( (acc,cur) => {
        // useFinger : ์–ด๋–ค ์†๊ฐ€๋ฝ์œผ๋กœ ๋ˆŒ๋ €๋Š”์ง€ ์ตœ์ข… ๋ฆฌํ„ด๊ฐ’("L", "R")
        // target : ์™ผ์†์ธ์ง€ ์˜ค๋ฅธ์†์ธ์ง€ ("left", "right")
        // number : ์ตœ์ข…์ ์œผ๋กœ ๋ˆ„๋ฅธ ๋ฒˆํ˜ธ ํ‚คํŒจ๋“œ (์ˆซ์ž, 0~9)
        let [ useFinger, target, number] =  ["" , "" , 0 ]
        
        if (leftNumbers.includes( cur ) ){
            [useFinger, target, number] = ["L", "left", cur]
        } else if ( rightNumbers.includes(cur) ) {
            [useFinger, target, number] = ["R", "right", cur]
        } else {
            const locationObj = Object.entries( current ).reduce( ( acc2, cur2) => {
                const targetHand = cur2[0]
                
                cur = cur === 0 ? 11 : cur
                let location = Math.abs(cur - cur2[1])
                
                if ( location >2 ) { //location >=3
                    location = Math.trunc(location / 3 + location %3)
                }
                acc2[ targetHand ] = location
                return acc2
            }, {})
            if ( locationObj["left"] === locationObj["right"] ){
                [useFinger, target, number ] = [
                    hand === "left" ? "L" : "R",
                    hand === "left" ? hand : "right",
                    cur
                ]
            } else if ( locationObj["left"] > locationObj["right"] ){
                [useFinger, target, number ] = [ "R", "right", cur ]
            } else {
                [useFinger, target, number ] = [ "L", "left", cur ]
            }
        }
        current[target] = number
				// console.log( cur, current, useFinger )
        return acc + useFinger
    }, "")
}

NestJS

๐Ÿ’กย ELK Stack ์€ ElasticSearch + Logstash + Kibana ์˜ ์กฐํ•ฉ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค! (์ผ๋ฐ˜์ ์œผ๋กœ)

ELK Stack - ElasticSearch / Logstash / Kibana

Untitled

์ธ๋ฑ์Šค(Index) vs ์—ญ์ธ๋ฑ์Šค(Inverted Index)