โฌ๏ธ Main Note
https://docs.google.com/document/d/1gK7xsH7GOBUNFVCbZtZ0Z0rL87pw8pvoK0G50tryWZg/edit
It is useful when a frontend developer makes a program without any backend developers.
Public API looks like the table below. (github)
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>
)
}
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;
} //๊ฐ์ ๋ฐฐ์ด์ ๋์ผํ ์ธ๋ฑ์ค๋ก ์ ๊ทผํ ์ ์๋ค
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
}
filter()
Methodfunction myFilter(array, callbackFn) {
let newArray = [];
for (let i = 0; i<array.length; i++){
callbackFn(array[i], i) && newArray.push(array[i])
}
return newArray
}