Skip to content

[최재영] 8_3#70

Merged
goawmfhfl merged 7 commits into
masterfrom
goawmfhfl/8_3
Sep 4, 2021
Merged

[최재영] 8_3#70
goawmfhfl merged 7 commits into
masterfrom
goawmfhfl/8_3

Conversation

@goawmfhfl
Copy link
Copy Markdown
Contributor

3-1 회문 문자열

문제 접근 방법

  • indexOf를 통해서 접근해보자
  • toLowerCase를 통해서 전달받은 문자열을 전부 소문자로 만들어버리자.

아쉬웠던 점

  • reverse 메서드를 활용할 생각을 하지 못함

배운점

  • string.split('').reverse().join('') 을 통해서 문자열을 뒤집을 수 있다 !

3-2 유효한 팰린드롬

문제 접근 방법

  • 정규표현식을 사용해서 문자열만 추출
  • toLowerCase를 활용해서 문자열을 소문자로 변환
  • for문을 활용해서 0번째 인덱스와 마지막 인덱스를 비교
  • 조건문에서 비교할 때는 이전에 배운 reverse메서드 사용해서 비교

아쉬웠던 점

  • 정규표현식을 이 상황에서 어떻게 적용해야하는지 몰랐음
  • 배열로 전달받은 문자열에 toLowerCase를 적용시키는 방법을 몰랏음.
  • let str ="found7, time:, study, Yduts;, emit, 7Dnuof" 이런식으로 전달받는 줄 몰랐음
  • 알파벳 이외의 문자라서 숫자도 없애야 한다는 것을 인지하지 못함.

배운점

  • 정규식표현와 replace 메서드의 활용방법
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replace('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"

const regex = /Dog/i;
console.log(p.replace(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"

3-3 숫자만 추출

문제 접근 방법

  • 강의를 보고선 힌트를 받음
  • isNaN를 사용하기
  • parseint 를 사용하기

해결과정

  • if(!isNaN(x)) answer = answer*10+Number(x);
  • answer에는 값이 계속 할당되게함
  • *10으로 인해서 앞에 앞에 나오는 0들은 answer에 할당이 되지 않음
  • 숫자를 만나면 그 때부터 *10+Number(x)로 인해서 배열에 push 하듯이 추가됨
// Example
0 x 10 + 0 = 0
0 x 10 + 2 = 2
2 x 10 + 4 = 24
24 x 10 + 6 = 246
246 x 10 + 1 = 2461

3-4 가장 짧은 문자거리

문제 접근 방법

  • 새로운 객체를 만들어준다
  • 객체의 item에는 0으로 초기화해준다
  • for문을 통해서 앞으로 한 번 뒤로 한 번 돌면서 가장 짧은 문자거리를 구한다.

아쉬웠던 점

  • 배열을 반대로 열거했을 때 어떤 조건을 입력해야 할 지 몰랐음
  • 최솟값을 구할 때 Math.min을 사용할 것 !

해결과정

  • answer[i]= Math.min(answer[i],cnt) 역 방향 최소 거리값 구하기

3-5 문자열 압축

문제 접근 방법

  • for문을 돌면서 arr[i] arr[i+1] 번째의 값들을 비교한다.
  • 조건식으로 (arr[i] === arr[i+1]) 인 상황에서 cnt 변수에 카운팅을 해준다.
  • else문을 만나면 값을 배열에 push한다

아쉬웠던 점

  • K2H1S7E1 라는 정답이 나왔음 1을 어떻게 처리해야하는지 몰랐음
  • if else문에서 else문에 if 조건문을 넣을 생각을 못함.

해결과정

  • if(cnt>1) answer.push(String(cnt)) 로 인해서 1을 처리해주었다 !
    • 1을 통하여 길이 값 맞춰주기

Comment thread goawmfhfl/3_1.js Outdated

function solution(s){
let answer = "NO"
let lowerCase = s.toLowerCase()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 변수는 상수로 쓰이기 땜에 const로 선언해주시는게 좋을것 같습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 ! 수정했습니다 피드백감사합니다 👍

Comment thread goawmfhfl/3_3.js
let answer = ''

for(let x of arr){
if(!isNaN(x)) answer+=x
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔하네요!

let키워드를 const키워드로 바꿨습니다 !
@goawmfhfl goawmfhfl merged commit fa654e0 into master Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants