Be well coding/In Immersive
6/12 / react
be well
2019. 6. 13. 22:21
Toy 06번 문제
string 1 과 string2 를 비교해서 가지고 있는 같은 char 를 리턴하는 문제.
ㄴ 해결 실패.. 충분히 할 수 있을 것 같았는데.. 요즘 알고리즘이 엄청 날 괴롭힌다.. 분명 풀 것 같은 문제들도 모두 틀려버린다.
++ 해결
var commonCharacters = function(string1, string2) {
let result = '';
for(let i = 0; i < string1.length; i++) {
let count = 0;
for(let j = 1; j < arguments.length; j++) {
if(arguments[j].includes(string1[i])) {
count++;
if(count === arguments.length - 1) {
result = result + string1[i];
}
}
}
// if(string2.indexOf(string1[i]) !== -1) {
// result = result + string1[i];
// }
}
return result;
};
리액트 스프린트 시작.
영상 넘어오는 거 까지 구현 성공.
class function 차이
class.
고유한 state를 가질 수 있다.
this.props 로 props 를 상속 받는다.
constructor 와 render() 를 가진다.
function
props 로 props 를 상속 받는다.
lass App extends React.Component {
constructor(props) {
super(props);
console.log([props]);
this.state = {
num: 0,
data: fakeData,
searchQ: 2002,
init: 2002
};
onTitleClick(idx) {
this.setState({
num: idx
});
}
setState 를 이용해서 state 의 값을 바꿔준다.
자식 컴포넌트에서 사용하려면 bind 로 묶거나 arrow function 을 써서 props 로 전달해주어야 한다.