Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/PROBLEM1.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@
| [97, 98] | [197, 198] | 0 |
| [131, 132] | [211, 212] | 1 |
| [99, 102] | [211, 212] | -1 |

<!-- 배열 줌 => 계산 => 승자
배열 사용 인덱스 이용

1.인덱스 가지고 둘 다 구해야 하니 인덱스를 이용해서 제일 큰
숫자를 구하는 함수 만들기
들어가는 것 : a[0]
문제 : string으로 바꾸니 [1,2]가 아니라 ["1","2"]이렇게 됨
=> Array.from(String(num))
=> parseInt()
2.가지고 fun(pobi) fun(crong)이용해서 승자 계산 후 출력 -->
30 changes: 30 additions & 0 deletions docs/PROBLEM2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,33 @@
| "browoanoommnaon" | "brown" |
| "zyelleyz" | "" |

<!--
1->2 : oomm 이 삭제 (바로 붙은것)
2->3 : nn이 바로 붙어서 삭제
3-> 4 :

결론 : 바로 붙은 문자는 둘 다 삭제한다.



1.문자열 받으면 처음과 바로 다음꺼 확인하기 => map이네
const a = "browoanoommnaon";
let t = Array.from(a).filter((item, index, arr) => {
return item !== arr[index + 1];
});
console.log(t);

['b', 'r', 'o', 'w', 'o', 'a', 'n', 'o', 'm', 'n', 'a', 'o', 'n']
browoannaon
왜 다를까..

유레카!
리턴에 조건을 하나 더 추가해서 앞 뒤가 둘 다 다른 애만 필터링하면 되는구나
['b', 'r', 'o', 'w', 'o', 'a', 'n', 'n', 'a', 'o', 'n']

이제 이걸 반복하기만 하면 되는거지

처음에 받고

문제 : 배열은 참조 타입이라 비교가 안된다...
=> 문자열로 바뀐 형태를 비교하면 가능
31 changes: 28 additions & 3 deletions docs/PROBLEM3.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@
### 실행 결과 예시

| number | result |
| --- | --- |
| 13 | 4 |
| 33 | 14 |
| ------ | ------ |
| 13 | 4 |
| 33 | 14 |

<!--
반복할 때 3,6,9가 있는지 확인하는 것이 중요하겠다
그러면 푸시해서 그 배열을 만들고 filter를 사용하면
될꺼 같아

포함하는지 확인하려면 includes()를 쑤자
includes를 쓸 때 메서드가 안먹혀

=>아 숫자 배열 말고 문자 배열로 만들면 includes()를 쓸 수 있겠구나

틀린 이유 : 33같이 3이 두개면 +2로 쳐야 함
그러면 어차피 배열로 모았으니까 그걸 다시 문자열로 변환한 다음에
그 문자열을 한개씩 쪼갠 배열의 길이를 구하면 될꺼가 ㅌ아

그러면 첫번 째는 일단 3,6,9가 있는 애들만 모으고
두번째는 3,6,9만 모은다







-->
39 changes: 35 additions & 4 deletions docs/PROBLEM4.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

엄마 말씀 word가 매개변수로 주어질 때, 아래 청개구리 사전을 참고해 반대로 변환하여 return 하도록 solution 메서드를 완성하라.

| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Z | Y | X | W | V | U | T | S | R | Q | P | O | N | M | L | K | J | I | H | G | F | E | D | C | B | A |
| Z | Y | X | W | V | U | T | S | R | Q | P | O | N | M | L | K | J | I | H | G | F | E | D | C | B | A |

### 제한사항

Expand All @@ -16,6 +16,37 @@

### 실행 결과 예시

| word | result |
| --- | --- |
| word | result |
| ------------ | ------------ |
| "I love you" | "R olev blf" |

그러면 아스키 코드 또는 배열로 정해놓고 전체에서 빼서 돌리는 것도 있겠다...

알파벳 : 26개 0부터 25
0이면 25 = 25
10이면 15 = 25
12이면 13 = 25

m과 n이 제일 가깝고 서로 바뀜

아 n과 25-n의 인덱스 !

배열을 푸시해서 만들고
word의 인덱스를 하나하나 map으로 25-n을 해서 다시 만들고 문자열로 만들면 되겠다!
그리고 소문자로 받았으니 나중에 따로 대문자로 만들어주면 될꺼같은데?

문자열 => 97~122 니까 아스키 코드로 받은 수를 122에 빼면 인덱스 번호가 될듯?

근데 아스키 코드 안쓰니까 너무 복잡하다...
그냥 아스키 코드 쓰면서 하자
아스키 코드로 변환해주는 함수는 charCodeAt()
아스키 코드를 문자로 변환하는 함수는 fromCharCode()

받아와서 charCodeAt() 하고 122-코드번호 하면 처음에 만든 배열에서
문자 받아오고

// 해결 : 띄어쓰기(3) , 대소문자(2) , 알파벳 역전(1)
// 1.다 바꾼 상태
// 2.공백 대문자 소문자
// 3.공백이면 32 그대로 / 소문자면 122 - 인덱스 번호 / 대문자면 122 -인덱스번호 소문자 소문자에 toUpperCase()
// 4.문자열 합치기
25 changes: 21 additions & 4 deletions docs/PROBLEM5.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@

### 실행 결과 예시

| money | result |
| --- | --- |
| 50237 | [1, 0, 0, 0, 0, 2, 0, 3, 7] |
| 15000 | [0, 1, 1, 0, 0, 0, 0, 0, 0] |
| money | result |
| ----- | --------------------------- |
| 50237 | [1, 0, 0, 0, 0, 2, 0, 3, 7] |
| 15000 | [0, 1, 1, 0, 0, 0, 0, 0, 0] |

9자리 배열
5만원 0 or 1 , 1만원
오천원 0 or 1, 천원
오백원 0 or 1, 백원
오십원 0 or 1, 십원
일원

수가 크니까
결국 나머지로 가야해
50000으로 나누고 그 수 받고 나머지로 다시 실행
그 나머지를 10000으로 나누고 그 수 받고 나머지로 다시 실행
.........쭉

맵 돌리려면 먼저 나누고 나머지 구해야 하는데...return 때문에 안되네 순서가..

돈을 두개로 나누기
20 changes: 17 additions & 3 deletions docs/PROBLEM6.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

혼란을 막기 위해 크루들의 닉네임 중 **같은 글자가 연속적으로 포함** 될 경우 해당 닉네임 사용을 제한하려 한다. 이를 위해 같은 글자가 연속적으로 포함되는 닉네임을 신청한 크루들에게 알려주는 시스템을 만들려고 한다.


신청받은 닉네임 중 **같은 글자가 연속적으로 포함** 되는 닉네임을 작성한 지원자의 이메일 목록을 return 하도록 solution 메서드를 완성하라.

### 제한사항
Expand All @@ -18,6 +17,21 @@

### 실행 결과 예시

| forms | result |
| --- | --- |
| forms | result |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [ ["jm@email.com", "제이엠"], ["jason@email.com", "제이슨"], ["woniee@email.com", "워니"], ["mj@email.com", "엠제이"], ["nowm@email.com", "이제엠"] ] | ["jason@email.com", "jm@email.com", "mj@email.com"] |

같은 글자 두개 이상 잡아내기
객체 배열 이다

이름만 받아서 두개 이상 잡아내고
해당 인덱스에 있는 이메일 출력 하면 끝

result는 이메일에 해당하는 부분의 문자열을 오름차순으로 정렬하고 중복은 제거한다.

하나의 문자열이 포함된지 한번 필터
하나의 문자열 + 원하는 문자열 필터
필터 된 것을 가지고 다시 이메일을 찾는 과정
=> 배열에서 문자를 다시 가져와서
객체배열에 다시 필터
인덱스 번호로 이메일 가져오기
17 changes: 16 additions & 1 deletion docs/PROBLEM7.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 🚀 기능 요구 사항

레벨 2의 팀 프로젝트 미션으로 SNS(Social Networking Service)를 만들고자 하는 팀이 있다. 팀에 속한 크루 중 평소 알고리즘에 관심이 많은 미스터코는 친구 추천 알고리즘을 구현하고자 아래와 같은 규칙을 세웠다.
- 사용자와 함께 아는 친구의 수 = 10점

- 사용자와 함께 아는 친구의 수 = 10점
- 사용자의 타임 라인에 방문한 횟수 = 1점

사용자 아이디 user와 친구 관계를 담은 이차원 배열 friends, 사용자 타임 라인 방문 기록 visitors가 매개변수로 주어질 때, 미스터코의 친구 추천 규칙에 따라 점수가 가장 높은 순으로 정렬하여 최대 5명을 return 하도록 solution 메서드를 완성하라. 이때 추천 점수가 0점인 경우 추천하지 않으며, 추천 점수가 같은 경우는 이름순으로 정렬한다.
Expand All @@ -23,3 +24,17 @@
| user | friends | visitors | result |
| ------ | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ------------------------- |
| "mrko" | [ ["donut", "andole"], ["donut", "jun"], ["donut", "mrko"], ["shakevan", "andole"], ["shakevan", "jun"], ["shakevan", "mrko"] ] | ["bedi", "bedi", "donut", "bedi", "shakevan"] | ["andole", "jun", "bedi"] |

// 1.추천 친구 리스트 ( 객체 형식)
// -사용자가 아는 친구 배제
// 2.추천 함수
// -함께 아는 친구 + 10
// -방문친구 + 1
// 로 각 점수를 넣어줌 (객체)

// 3.추천 친구 객체보고 순위 정하기
// -0점 빼고
// -최대 5명
// -점수를 오름차순으로
// -점수가 같으면 이름순
// 배열로 결과 출력
29 changes: 28 additions & 1 deletion src/problem1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
function problem1(pobi, crong) {
var answer;
if (pobi[0] + 1 === pobi[1] && crong[0] + 1 === crong[1]) {
const big = (a) => {
let result1 = 0;
let result2 = 1;

Array.from(String(a)).forEach((num) => {
result1 += parseInt(num);
result2 *= parseInt(num);
});
return result1 >= result2 ? result1 : result2;
};

const total = (leftRight) => {
return big(leftRight[0]) >= big(leftRight[1])
? big(leftRight[0])
: big(leftRight[1]);
};

if (total(pobi) > total(crong)) {
answer = 1;
} else if (total(pobi) < total(crong)) {
answer = 2;
} else {
answer = 0;
}
} else {
answer = -1;
}
return answer;
}

Expand Down
15 changes: 15 additions & 0 deletions src/problem2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
function problem2(cryptogram) {
var answer;
let setArray = Array.from(cryptogram);

for (let i = 0; i < cryptogram.length; i++) {
let newArray;
newArray = setArray.filter((item, index, Aarry) => {
return item !== Aarry[index + 1] && item !== Aarry[index - 1];
});

if (newArray.join("") !== setArray.join("")) {
setArray = newArray;
} else {
answer = newArray.join("");
return answer;
}
}
return answer;
}

Expand Down
17 changes: 17 additions & 0 deletions src/problem3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
function problem3(number) {
var answer;
let setArray = [];

for (let i = 1; i <= number; i++) {
setArray.push(String(i));
}

const newArray1 = setArray.filter((num) => {
return num.includes(3) || num.includes(6) || num.includes(9);
});

const newArray2 = newArray1.join("").split("");

const total = newArray2.filter((num) => {
return num.includes(3) || num.includes(6) || num.includes(9);
});

answer = total.length;
return answer;
}

Expand Down
19 changes: 19 additions & 0 deletions src/problem4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
function problem4(word) {
var answer;
const setArray = Array.from(word);
console.log(setArray);

const setAlphabat = setArray.map((str) => {
return str.charCodeAt();
});

const newArray = setAlphabat.map((item) => {
if (item < 65) {
return (item = String.fromCharCode(32));
} else if (65 <= item && item <= 90) {
return (item = String.fromCharCode(122 + 65 - item).toUpperCase());
} else {
return (item = String.fromCharCode(122 + 97 - item));
}
});

answer = newArray.join("");

return answer;
}

Expand Down
13 changes: 13 additions & 0 deletions src/problem5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
function problem5(money) {
var answer;

const setMoney = [50000, 10000, 5000, 1000, 500, 100, 50, 10, 1];

let calMoney = money;
const cal = setMoney.map((mon) => {
let moneyDivide = calMoney;
let moneyRemain = calMoney;
calMoney = moneyDivide % mon;
return parseInt(moneyRemain / mon);
});

answer = cal;

return answer;
}

Expand Down
Loading