Skip to content

Commit ac0313e

Browse files
LerryLerry
authored andcommitted
[solve] mapAppendOrder
1 parent 724dc49 commit ac0313e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 설명
2+
3+
배열의 값을 name 프로퍼티에 넣고 몇번째 원소인지를 order에 넣은 객체의 배열을 출력하세요
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
const resultArray = [];
4+
inputArray.forEach((elem, index) => {
5+
resultArray.push({
6+
"name": elem,
7+
"order": index + 1,
8+
});
9+
});
10+
return resultArray;
11+
}
12+
13+
exports.solution = solution;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: ['홍길동', '둘리', '루피'],
5+
answer: [
6+
{ name: '홍길동', order: 1 },
7+
{ name: '둘리', order: 2 },
8+
{ name: '루피', order: 3 },
9+
],
10+
};
11+
12+
describe('mapAppendOrder', () => {
13+
test('test1', () => {
14+
expect(solution(test1.input)).toEqual(test1.answer);
15+
});
16+
});

0 commit comments

Comments
 (0)