๐Ÿ‹ TIL 0204

JBยท2022๋…„ 2์›” 4์ผ
0

CodeCamp FE 05

๋ชฉ๋ก ๋ณด๊ธฐ
17/33

โฌ‡๏ธ Main Note
https://docs.google.com/document/d/1gK7xsH7GOBUNFVCbZtZ0Z0rL87pw8pvoK0G50tryWZg/edit

๐ŸงŠ [Open-API]

It is useful when a frontend developer makes a program without any backend developers.
Public API looks like the table below. (github)

  • API-key: Exists to prevent million times of requests.
    --> Able to use only when the user signed up to the API and gets the key of it.
import {useEffect, useState} from "react"
import axios from 'axios'

export default function OpenApiPage () {

    const [dogUrl, setDogUrl]= useState("")
    
    useEffect(() => {
        const fetchDog = async () => {
            const result =  await axios.get("https://dog.ceo/api/breeds/image/random")
            //API ์‚ฌ์ดํŠธ ์ž์ฒด๋ฅผ ํ•ด์ค˜์•ผํ•จ ๊ฑฐ๊ธฐ์„œ message, status ๊ณจ๋ผ์„œ ๋ฐ›์•„์˜ค๋Š”๊ฒƒ
            setDogUrl(result.data.message)// promise๊ฐ€ ๋œจ๊ฒŒ ๋˜๋Š”๋ฐ ์ด๊ฑด ๋น„๋™๊ธฐํ˜•์‹์ด๋ผ ์–ธ์  ๊ฐ€ result ํ™”๋ฉด์— ๋ณด์—ฌ์ค„๊ฒŒ ํ•˜๊ณ  ๋งํ•˜๋Š”๊ฒƒ
                                                //--> ์ด๋ ‡๊ฒŒ ์•ˆ์— ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋„ฃ์–ด์ค˜์•ผ async ์‚ฌ์šฉ ๊ฐ€๋Šฅ
        }
        fetchDog()
    }, []) //๋นˆ array๋Š” ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰ํ•˜๊ณ  ๊ทธ ๋’ค๋กœ๋Š” ์‹คํ–‰ ์•ˆํ•œ๋‹ค๋Š”๊ฒƒ

    return (
        <div>
            <div>์˜คํ”ˆ API ์—ฐ์Šต</div>
            <img src={dogUrl} width="50%" height="50%"/>
        </div>
    )
}

๐ŸŽ [Backend Architecture]

How the Server Structure is Generated

DataBase Structure

DataBase Management System


๐Ÿฅฃ [Algorithms - Overall]

Factorial!

function solution(a, b) {
    let answer = 0;
    
    for(let i = 0; i<a.length; i++){
        const sum = a[i] * b[i]
        answer += sum
    }
    return answer;
} //๊ฐ™์€ ๋ฐฐ์—ด์€ ๋™์ผํ•œ ์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค

Removing the Smallest Number

function solution(arr) {
    const answer = []
    
    let min = arr[0]
    for(let i=1;i<arr.length; i++){
        if(min>arr[i]){
            min = arr[i]
        }
    }
    for (let i=0;i<arr.length; i++){
        if(arr[i] !==min){
            answer.push(arr[i])
        }
    }
    return answer.length === 0 ? [-1] : answer
}

Building filter() Method

function myFilter(array, callbackFn) {
    let newArray = [];
    for (let i = 0; i<array.length; i++){
        callbackFn(array[i], i) && newArray.push(array[i])
    }
    return newArray
}
profile
๋‘๋น„๋‘๋ฐฅ๋ฐฅ

0๊ฐœ์˜ ๋Œ“๊ธ€