엉덩엉덩.. 오른쪽 가동범위가 별로,..
s는 여러 괄호들로 이루어진 String 인자입니다.
s가 유효한 표현인지 아닌지 true/false로 반환해주세요.
종류는 '(', ')', '[', ']', '{', '}' 으로 총 6개 있습니다.
function isValid(s){
const obj = {'(':')', '{':'}', '[':']'}
let value = s[s.length/2] // value
let key = s[s.length/2-1] //key
if (s%2===0 && obj[key] === value){
return true
}
else {
return false
}
}
s가 '(){}'일 경우 내가 변수로 지정한 key값은 ')' value값은 '{'가 된다.
-> 예외 처리 방법 생각해보기
로그인 버튼 클릭 시 fetch 함수 실행
json.stringify
.then
response를 받아온 다음 실행되는 부분fetch("url",{
method:"",
body: JSON.stringify({
email:this.state.id,
password: this.state.password,
}),
})
.then((res)=>res.json());
.then((result) => console.log('결과: ',result)
// 로그인버튼 클릭 시 실행되는 함수
goToMain = (e) => {
// form태그의 submit기능이 실행되지 않도록 하기
e.preventDefault();
fetch("http://10.58.3.143:8000/user/signin",{
method:"POST",
body: JSON.stringify({
email: this.state.userId,
password: this.state.userPassword
})
})
.then(res => res.json())
// ID와 password가 확인됐을 때 SUCCESS 메세지를 받아 main으로 이동하거나 알람 띄우기.
.then(result => result.message === "SUCCESS" ?
this.props.history.push('/main-naeunsong') : alert("아이디와 비밀번호를 확인해주세요"))
}
백엔드 개발자와 소통할 때 필요한 것
1. API 주소
2. method 확인
3. body에 담긴 key값 확인
4. message값 확인