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
9 changes: 9 additions & 0 deletions Challenge/yuzunsang/everyArray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 문제제목

## 설명

every를 이용해서 모든 원소가 짝수인지 아닌지를 판별하세요

## Expected Output

true
7 changes: 7 additions & 0 deletions Challenge/yuzunsang/everyArray/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function solution(inputArray) {
const result = inputArray.every((el) => el % 2 === 0);

return result;
}

exports.solution = solution;
21 changes: 21 additions & 0 deletions Challenge/yuzunsang/everyArray/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { solution } = require("./solve");

const test1 = {
input: [2, 4, 6, 8, 10],
answer: true,
};

const test2 = {
input: [2, 3, 6, 8, 10],
answer: false,
};

describe("everyArray", () => {
test("모두 짝수면 true여야 한다.", () => {
expect(solution(test1.input)).toEqual(test1.answer);
});

test("홀수가 있으면 false여야 한다.", () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/expDivOdd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

제곱한 후 3으로 나눈 나머지가 홀수인 것 을 뽑은 배열의 총 합을 구하세요.
13 changes: 13 additions & 0 deletions Challenge/yuzunsang/expDivOdd/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function solution (inputArray) {
let ansArray = [];

for (let i = 0; i < inputArray.length; i++) {
inputArray[i] **= 2;

if ((inputArray[i] % 3) % 2 === 1) ansArray.push(inputArray[i]);
}

return ansArray.reduce((a, b) => a + b);
}

exports.solution = solution;
21 changes: 21 additions & 0 deletions Challenge/yuzunsang/expDivOdd/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { solution } = require('./solve');

const test1 = {
input: [1, 7, 3, 4, 6],
answer: 66,
};

const test2 = {
input: [2, 3, 6, 8, 10],
answer: 168,
};

describe('everyArray', () => {
test('1, 7, 3, 4, 6', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});

test('2, 3, 6, 8, 10', () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/filterAge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

배열 원소의 age가 30이상 50미만인 사람만 있는 객체의 배열을 만드세요
7 changes: 7 additions & 0 deletions Challenge/yuzunsang/filterAge/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// write your codes
function solution(inputArray) {
const result = inputArray.filter((item) => item.age >= 30 && item.age < 50);
return result;
}

exports.solution = solution;
32 changes: 32 additions & 0 deletions Challenge/yuzunsang/filterAge/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { solution } = require('./solve');

const test1 = {
input: [
{
name: '영미',
age: 25,
},
{
name: '일미',
age: 35,
},
{
name: '이미',
age: 45,
},
{
name: '삼미',
age: 55,
},
],
answer: [
{ name: '일미', age: 35 },
{ name: '이미', age: 45 },
],
};

describe('filterAge', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
});
5 changes: 5 additions & 0 deletions Challenge/yuzunsang/filterIntersection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 문제제목

## 설명

두 배열의 교집합을 출력하세요!
7 changes: 7 additions & 0 deletions Challenge/yuzunsang/filterIntersection/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function solution (inputArray1, inputArray2) {
// filter는 배열에서 조건에 맞는 원소만을 남겨둘 때 사용
// includes는 어떠한 원소가 배열에 포함되어 있는 지를 boolean으로 반환
return inputArray1.filter((el) => inputArray2.includes(el));
}

exports.solution = solution;
15 changes: 15 additions & 0 deletions Challenge/yuzunsang/filterIntersection/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { solution } = require('./solve');

const test1 = {
input: {
A: [1, 2, 3, 4, 5],
B: [3, 4, 5, 6, 7],
},
answer: [3, 4, 5],
};

describe('filterIntersection', () => {
test('test1', () => {
expect(solution(test1.input.A, test1.input.B)).toEqual(test1.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/filterOdd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

홀수만 뽑아 배열로 만드세요
8 changes: 8 additions & 0 deletions Challenge/yuzunsang/filterOdd/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// write your codes

function solution(inputArray) {
// filter는 배열에서 조건에 맞는 원소만 남겨두는 것
return inputArray.filter((v) => v % 2 === 1);
}

exports.solution = solution;
28 changes: 28 additions & 0 deletions Challenge/yuzunsang/filterOdd/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { solution } = require('./solve');

const test1 = {
input: [4, 2, 5, 1, 3],
answer: [5, 1, 3],
};

const test2 = {
input: [4, 2, 6, 8, 50, 16],
answer: [],
};

const test3 = {
input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
answer: [1, 3, 5, 7, 9, 11],
};

describe('filterOdd', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
test('test2', () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
test('test3', () => {
expect(solution(test3.input)).toEqual(test3.answer);
});
});
9 changes: 9 additions & 0 deletions Challenge/yuzunsang/findWord/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 문제제목

## 설명

용가리라는 단어가 있으면 true 없으면 false를 출력

## Expected Output

true
6 changes: 6 additions & 0 deletions Challenge/yuzunsang/findWord/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// write your codes
function solution(inputArray) {
return inputArray.includes('용가리');
}

exports.solution = solution;
26 changes: 26 additions & 0 deletions Challenge/yuzunsang/findWord/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { solution } = require('./solve');

const test1 = {
input: ['잠', '자', '고', '싶', '다', '용가리'],
answer: true,
};
const test2 = {
input: ['맛있는', '용가리치킨'],
answer: false,
};
const test3 = {
input: ['고질라', '용가리 ', '울트라맨'],
answer: false,
};

describe('findWord', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
test('test2', () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
test('test3', () => {
expect(solution(test3.input)).toEqual(test3.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/forEachFilter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

배열 원소중 40 이상인 수만 뽑아 배열을 만드세요.
6 changes: 6 additions & 0 deletions Challenge/yuzunsang/forEachFilter/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// write your codes
function solution(inputArray) {
return inputArray.filter((el) => el >= 40);
}

exports.solution = solution;
12 changes: 12 additions & 0 deletions Challenge/yuzunsang/forEachFilter/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { solution } = require('./solve');

const test1 = {
input: [100, 10, 20, 40],
answer: [100, 40],
};

describe('forEachFilter', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/forEachFilterIsNaN/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

배열 원소중 숫자인 원소만 뽑아 배열을 만드세요.
6 changes: 6 additions & 0 deletions Challenge/yuzunsang/forEachFilterIsNaN/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// write your codes
function solution(inputArray) {
return inputArray.filter((el) => typeof el === 'number');
}

exports.solution = solution;
28 changes: 28 additions & 0 deletions Challenge/yuzunsang/forEachFilterIsNaN/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { solution } = require('./solve');

const test1 = {
input: [1, 40, '라매', '개발자', 51.5, 'a', 88],
answer: [1, 40, 51.5, 88],
};

const test2 = {
input: [1, 2, 3, '4', 5, '6'],
answer: [1, 2, 3, 5],
};

const test3 = {
input: [-3, -2, -1, 0, 1, 2, 3],
answer: [-3, -2, -1, 0, 1, 2, 3],
};

describe('forEachFilterIsNaN', () => {
test('test1: 숫자,문자 판별', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
test('test2: 문자로된 숫자 판별', () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
test('test3: 음수 양수 포함', () => {
expect(solution(test3.input)).toEqual(test3.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/forEachMap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

forEach 메소드를 사용해서 배열의 각 원소 끝에 '%'를 붙인 문자열 배열을 출력하세요
10 changes: 10 additions & 0 deletions Challenge/yuzunsang/forEachMap/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// write your codes
function solution(inputArray) {
const answer = [];

inputArray.forEach((item) => answer.push(`${item}%`));

return answer;
}

exports.solution = solution;
12 changes: 12 additions & 0 deletions Challenge/yuzunsang/forEachMap/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { solution } = require('./solve');

const test1 = {
input: [100, 10, 20, 40],
answer: ['100%', '10%', '20%', '40%'],
};

describe('forEachMap', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/forEachReduce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

forEach 메소드를 사용해서 배열의 총 합을 출력하는 코드를 작성하세요
10 changes: 10 additions & 0 deletions Challenge/yuzunsang/forEachReduce/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// write your codes
function solution(inputArray) {
let sum = 0;

inputArray.forEach((item) => sum += item);

return sum;
}

exports.solution = solution;
28 changes: 28 additions & 0 deletions Challenge/yuzunsang/forEachReduce/solve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { solution } = require('./solve');

const test1 = {
input: [100, 10, 20, 40],
answer: 170,
};

const test2 = {
input: [120, -20, -30, 0, 15],
answer: 85,
};

const test3 = {
input: [-10, -20, -30],
answer: -60,
};

describe('forEachReduce', () => {
test('test1', () => {
expect(solution(test1.input)).toEqual(test1.answer);
});
test('test2: 음수가 포함된 계산', () => {
expect(solution(test2.input)).toEqual(test2.answer);
});
test('test3: 음수만 존재하는 계산', () => {
expect(solution(test3.input)).toEqual(test3.answer);
});
});
3 changes: 3 additions & 0 deletions Challenge/yuzunsang/mapAddPercent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 설명

map 메소드를 사용해 배열 각각 숫자 뒤에 %를 붙인 문자열을 만드세요
6 changes: 6 additions & 0 deletions Challenge/yuzunsang/mapAddPercent/solve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// write your codes
function solution(inputArray) {
return inputArray.map((item) => `${item}%`);
}

exports.solution = solution;
Loading