목록전체 글 (86)
undefined

문제 설명 문제 풀이 function solution(s){ const arr = s.toLowerCase().split("") let answer let p = [] let y = [] for(let i = 0; i < arr.length; i++) { if(arr[i] === "p") { p.push("p") } else if (arr[i] === "y") { y.push("y") } } p.length === y.length ? answer = true : answer = false return answer } 1. 문자열을 split으로 쪼갠 배열을 for루프를 돌림 2. i번째 배열요소가 p이면 p에 y면 y에 집어넣음 3. 길이비교 후 리턴 개선 사항 function solution(s){ ..

문제 설명 문제 풀이 function solution(seoul) { const index = seoul.indexOf("Kim") return `김서방은 ${index}에 있다` } 1. Kim의 위치 찾기 2. ``이용하여 리턴 개선 사항

문제 설명 문제 풀이 function solution(n) { const array = Array(n+1).fill(true).fill(false,0,2) const answer = [] for(let i = 2; i 배수를 구하는 식 // 모든 배수를 구하여 false로 바꿔준다. 5. 이후 array.filter(e=>e)로 true의 값만 리턴 배운 점 1. 불리언 값을 이용하여 소수를 찾았다는 점 => 숫자값을 이용했으면 일일이 배열에서 빼내줘야 했을 것임 2. fill의 실사용 3. j+=i 라는 배수를 구하는 식의 활용 4. filter(e=>e)를 사용하면 true의 값만 리턴한다는 사실

문제 설명 문제 풀이 function solution(s, n) { const upAlphaInner = Array.from(Array(26)).map((t,i) => i + 65) const loAlphaInner = Array.from(Array(26)).map((t,i) => i + 97) const upAlphabet = upAlphaInner.map(t => String.fromCharCode(t)) const loAlphabet = loAlphaInner.map(t => String.fromCharCode(t)) let answer = "" for(let i = 0; i < s.length; i++) { let char = s[i] if(char === " ") { answer += " " c..

문제 설명 문제 풀이 function solution(n) { let result = 0 for(let i = 1; i

문제 설명 문제 풀이 function solution(s) { const word = s.split(" ") const result = [] for(let i = 0; i j%2 ? t.toLowerCase() : t.toUpperCase()).join("")) } return result.join(" ") } 1. split으로 단어단위로 쪼개준다. 2. for루프를 활용해서 각 단어마다 method를 적용시킨다. 3. word에 다시 split하여 char단위로 쪼개준다. 4. map을 이용해 인덱스를 2로 나눠준 후 나머지 값이 false일때 대문자로 바꿔준다. (0과 짝수값찾기) 5..