Skip to content

Commit 9548e87

Browse files
authored
Merge pull request #170 from lerrybe/master
[JS Array Challenge]
2 parents 21bfc53 + 7f2ee63 commit 9548e87

File tree

24 files changed

+466
-0
lines changed

24 files changed

+466
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## 설명
2+
3+
점수를 계산해서 점수가 높은 순으로 name과 score를 가진 객체의 배열을 출력하세요.
4+
단 실격자는 출력하지 않습니다.
5+
6+
### 피겨 점수 기준
7+
8+
피겨 점수는 ‘기술점수(TES)+예술점수(PCS)-감점’으로 구성된다.
9+
10+
기술점수(TES·Total Element Score)는 기본점수에 수행점수(GOE·Grade Of Execution)를 합산해 도출한다.
11+
12+
심판은 선수들이 점프와 스핀의 기술을 제대로 수행하는지 살핀다. 점프에선 회전수를 제대로 지켰는지, 에지를 제대로 사용했는지에 따라 ‘롱 에지’(잘못된 에지 사용)나 ‘다운그레이드’(난이도 하락), ‘어텐션’(주의) 등의 판정을 내린다. 스핀과 스텝시퀀스에 붙는 레벨(1~4)도 이들이 결정한다.
13+
14+
9명의 심판은 선수들이 미리 제출한 연기 구성표를 기준으로 과제별 기본점수에서 가·감점을 한다. 이른바 ‘GOE’라 불리는 수행점수다.
15+
16+
쇼트프로그램은 점프 3개, 스핀 3개, 스텝 1개의 수행과제가 반드시 포함돼야 한다.
17+
18+
예술점수(PCS·Total Program Component Score)는 프로그램의 완성도에 영향을 미치는 스케이팅 기술·동작의 연결·연기·안무·곡 해석 등 5가지를 평가한다.
19+
20+
마지막으로 감점이 반영된다. 감점 항목이 발생할 때마다 1점씩 감점된다.
21+
22+
원문보기:
23+
http://news.khan.co.kr/kh_news/khan_art_view.html?art_id=201402172146545#csidx6329aebb6a02152bca884614a7f0544
24+
25+
### 판정 기준
26+
27+
- 점수가 가장 높은 사람이 1등이다.
28+
- 점수는 기술점수(TES) + 예술점수(PCS) - 감점 으로 구성된다.
29+
- 기술점수(TES)는 기본점수 \* 수행점수(GOE)를 합산해 도출한다.
30+
- 필수 수행과제를 수행하지 못했을 시 실격이다.
31+
32+
### 필수 수행과제
33+
34+
- 쇼트프로그램은 점프 3개, 스핀 3개, 스텝 1개의 수행과제가 반드시 포함돼야 한다.
35+
- 점프와 스핀을 4번 이상 수행했을 시 가장 잘한 3개를 기준으로 한다.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// 기본 점수
2+
const baseScore = {
3+
jump: 10,
4+
spin: 20,
5+
step: 15,
6+
};
7+
8+
const baseAssignment = {
9+
jump: 3,
10+
spin: 3,
11+
step: 1,
12+
};
13+
14+
// write your codes
15+
16+
function solution(inputArray) {
17+
targetArray = [];
18+
19+
inputArray.forEach((obj) => {
20+
const jumpCondition = (obj.goe.jump.length >= baseAssignment.jump);
21+
const spinCondition = (obj.goe.spin.length >= baseAssignment.spin);
22+
const stepCondition = (obj.goe.step.length >= baseAssignment.step);
23+
24+
if (jumpCondition && spinCondition && stepCondition) {
25+
obj.goe.jump.sort((a, b) => b - a);
26+
obj.goe.spin.sort((a, b) => b - a);
27+
obj.goe.step.sort((a, b) => b - a);
28+
29+
let jumpScore = 0;
30+
for (let i = 0; i < baseAssignment.jump; i++) {
31+
jumpScore += obj.goe.jump[i] * baseScore.jump;
32+
}
33+
let spinScore = 0;
34+
for (let i = 0; i < baseAssignment.spin; i++) {
35+
spinScore += obj.goe.spin[i] * baseScore.spin;
36+
}
37+
let stepScore = 0;
38+
for (let i = 0; i < baseAssignment.step; i++) {
39+
stepScore += obj.goe.step[i] * baseScore.step;
40+
}
41+
42+
const totalScore = jumpScore + spinScore + stepScore + obj.pcs - obj.penalty;
43+
44+
targetArray.push({ name: obj.name, score: totalScore });
45+
}
46+
});
47+
48+
return targetArray;
49+
}
50+
51+
exports.solution = solution;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [
5+
{
6+
name: '김연아',
7+
goe: {
8+
jump: [10, 9, 10],
9+
spin: [10, 10, 10],
10+
step: [9],
11+
},
12+
pcs: 30,
13+
penalty: 0,
14+
},
15+
{
16+
name: '피겨의 신',
17+
goe: {
18+
jump: [10000, 10000],
19+
spin: [10000, 10000, 10000],
20+
step: [10000],
21+
},
22+
pcs: 100000,
23+
penalty: 0,
24+
},
25+
{
26+
name: '아사다 마오',
27+
goe: {
28+
jump: [9, 6, 8, 9],
29+
spin: [9, 9, 9],
30+
step: [8],
31+
},
32+
pcs: 29,
33+
penalty: 10,
34+
},
35+
],
36+
answer: [
37+
{ name: '김연아', score: 1055 },
38+
{ name: '아사다 마오', score: 939 },
39+
],
40+
};
41+
42+
describe('everyArray', () => {
43+
test('test1', () => {
44+
expect(solution(test1.input)).toEqual(test1.answer);
45+
});
46+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 문제제목
2+
3+
## 설명
4+
5+
두 배열의 교집합을 출력하세요!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function solution(inputArray1, inputArray2) {
2+
return inputArray1.filter((elem) => inputArray2.includes(elem));
3+
}
4+
5+
exports.solution = solution;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: {
5+
A: [1, 2, 3, 4, 5],
6+
B: [3, 4, 5, 6, 7],
7+
},
8+
answer: [3, 4, 5],
9+
};
10+
11+
describe('filterIntersection', () => {
12+
test('test1', () => {
13+
expect(solution(test1.input.A, test1.input.B)).toEqual(test1.answer);
14+
});
15+
});

Challenge/lerrybe/filterOdd/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 설명
2+
3+
홀수만 뽑아 배열로 만드세요

Challenge/lerrybe/filterOdd/solve.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
return inputArray.filter(elem => elem % 2 !== 0);
4+
}
5+
6+
exports.solution = solution;
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [4, 2, 5, 1, 3],
5+
answer: [5, 1, 3],
6+
};
7+
8+
const test2 = {
9+
input: [4, 2, 6, 8, 50, 16],
10+
answer: [],
11+
};
12+
13+
const test3 = {
14+
input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
15+
answer: [1, 3, 5, 7, 9, 11],
16+
};
17+
18+
describe('filterOdd', () => {
19+
test('test1', () => {
20+
expect(solution(test1.input)).toEqual(test1.answer);
21+
});
22+
test('test2', () => {
23+
expect(solution(test2.input)).toEqual(test2.answer);
24+
});
25+
test('test3', () => {
26+
expect(solution(test3.input)).toEqual(test3.answer);
27+
});
28+
});

Challenge/lerrybe/findWord/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 문제제목
2+
3+
## 설명
4+
5+
용가리라는 단어가 있으면 true 없으면 false를 출력
6+
7+
## Expected Output
8+
9+
true

Challenge/lerrybe/findWord/solve.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
return inputArray.includes('용가리');
4+
}
5+
6+
exports.solution = solution;
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: ['잠', '자', '고', '싶', '다', '용가리'],
5+
answer: true,
6+
};
7+
const test2 = {
8+
input: ['맛있는', '용가리치킨'],
9+
answer: false,
10+
};
11+
const test3 = {
12+
input: ['고질라', '용가리 ', '울트라맨'],
13+
answer: false,
14+
};
15+
16+
describe('findWord', () => {
17+
test('test1', () => {
18+
expect(solution(test1.input)).toEqual(test1.answer);
19+
});
20+
test('test2', () => {
21+
expect(solution(test2.input)).toEqual(test2.answer);
22+
});
23+
test('test3', () => {
24+
expect(solution(test3.input)).toEqual(test3.answer);
25+
});
26+
});
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 문제제목
2+
3+
사용자가 안 본 광고는?
4+
5+
## 설명
6+
7+
유튜브는 사용자가 프리미엄 회원이 아닌 경우 영상 시작이나 중간에 광고가 나오도록 설정되어 있습니다.
8+
9+
[2020년 유튜브 인기 광고](https://www.thinkwithgoogle.com/intl/ko-kr/marketing-strategies/video/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD-youtube-%EC%9D%B8%EA%B8%B0-%EA%B4%91%EA%B3%A0%EC%98%81%EC%83%81-2020%EB%85%84-%EC%97%B0%EB%A7%90%EA%B2%B0%EC%82%B0/)는 총 열 편으로, 사용자의 일주일간 광고 시청 이력을 통해 해당 사용자가 일주일 동안 안 본 광고를 그 다음주에 노출함으로써 광고들이 사용자에게 골고루 노출되길 원합니다.
10+
11+
유저가 매일 유튜브에 접속하여 하루 한 편 이상의 광고를 보았다고 가정할 때, 이 유저가 안 본 광고는 무엇인지 출력해주세요.
12+
13+
## Expected Output
14+
15+
[ '동원F&B' ]
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const userHistory = [
2+
{ date: '2020-11-03', watched: ['KT', 'BBQ'] },
3+
{ date: '2020-11-04', watched: ['정관장', 'KT', '딱좋은데이'] },
4+
{ date: '2020-11-05', watched: ['그랑사가', '농심'] },
5+
{ date: '2020-11-06', watched: ['BBQ'] },
6+
{ date: '2020-11-07', watched: ['쌍용자동차', 'BBQ', 'KT'] },
7+
{ date: '2020-11-08', watched: ['켈로그코리아', '빙그레'] },
8+
{ date: '2020-11-09', watched: ['KT', '그랑사가', '빙그레'] },
9+
];
10+
11+
// write your codes
12+
function solution(inputArray) {
13+
inputArrayCopy = [...inputArray];
14+
userHistory.map((history) => {
15+
history.watched.map((ad) => {
16+
if (inputArrayCopy.includes(ad)) {
17+
const index = inputArrayCopy.indexOf(ad);
18+
delete inputArrayCopy[index];
19+
}
20+
})
21+
});
22+
23+
return inputArrayCopy.filter((elem) => elem !== undefined);
24+
}
25+
26+
exports.solution = solution;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [
5+
'동원F&B',
6+
'정관장',
7+
'KT',
8+
'BBQ',
9+
'그랑사가',
10+
'농심',
11+
'딱좋은데이',
12+
'빙그레',
13+
'쌍용자동차',
14+
'켈로그코리아',
15+
],
16+
answer: ['동원F&B'],
17+
};
18+
19+
describe('recommendAd', () => {
20+
test('test1', () => {
21+
expect(solution(test1.input)).toEqual(test1.answer);
22+
});
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 설명
2+
3+
입력받은 객채배열의 nickname을 key, name을 value로 하는 객체를 출력하세요
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
answer = {};
4+
inputArray.forEach(({ nickname, name }) => {
5+
answer[nickname] = name
6+
});
7+
return answer;
8+
}
9+
10+
exports.solution = solution;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [
5+
{
6+
name: '홍길동',
7+
nickname: 'hong',
8+
},
9+
{
10+
name: '둘리',
11+
nickname: '2li',
12+
},
13+
{
14+
name: '오스트랄로피테쿠스',
15+
nickname: '1Cin',
16+
},
17+
],
18+
answer: { hong: '홍길동', '2li': '둘리', '1Cin': '오스트랄로피테쿠스' },
19+
};
20+
21+
describe('reduceNameNickname', () => {
22+
test('test1', () => {
23+
expect(solution(test1.input)).toEqual(test1.answer);
24+
});
25+
});
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 문제제목
2+
3+
## 설명
4+
5+
배열안의 객체를 price를 기준으로 오름차순 정렬한 배열을 출력하세요
6+
7+
## Expected Output
8+
9+
[
10+
{ name: '사과', price: 1000 },
11+
{ name: '당근', price: 2000 },
12+
{ name: '수박', price: 5000 },
13+
{ name: '참외', price: 10000 }
14+
]
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
return inputArray.sort((a, b) => {
4+
return a.price - b.price;
5+
});
6+
}
7+
8+
exports.solution = solution;

0 commit comments

Comments
 (0)