Skip to content

Commit 6ac2176

Browse files
unn04012bona1122
authored andcommitted
[unn04012] 25.01.02 (codingTestStd#10)
* 배열 자르기, 기초 * 배열 회전시키기, 기초 * 제일 작은 수 제거하기, 중급 * 나누어 떨어지는 숫자 배열, 중급 * 행렬의 곱셈, 심화
1 parent 3277943 commit 6ac2176

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function solution(arr, divisor) {
2+
const answer = [];
3+
4+
for (const e of arr) {
5+
if (e % divisor === 0) answer.push(e);
6+
}
7+
if (answer.length === 0) answer.push(-1);
8+
9+
return answer.sort((a, b) => a - b);
10+
}
11+
12+
console.log(solution([5, 9, 7, 10], 5));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function solution(arr1, arr2) {
2+
const n = arr1.length;
3+
const m = arr2[0].length;
4+
5+
const answer = Array.from({ length: n }, () => Array(m).fill(0));
6+
7+
for (let i = 0; i < n; i++) {
8+
for (let j = 0; j < m; j++) {
9+
const result = arr1[i].reduce((acc, cur, idx) => acc + cur * arr2[idx][j], 0);
10+
11+
answer[i][j] = result;
12+
}
13+
}
14+
15+
return answer;
16+
}
17+
18+
console.log(
19+
solution(
20+
[
21+
[2, 3, 2],
22+
[4, 2, 4],
23+
[3, 1, 4],
24+
],
25+
[
26+
[5, 4, 3],
27+
[2, 4, 1],
28+
[3, 1, 1],
29+
]
30+
)
31+
);

unn04012/array/arr_rotate.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function solution(numbers, direction) {
2+
const answer = [];
3+
4+
if (direction === 'right') {
5+
for (let i = 0; i < numbers.length - 1; i++) {
6+
answer[i + 1] = numbers[i];
7+
}
8+
answer[0] = numbers[numbers.length - 1];
9+
} else {
10+
for (let i = numbers.length - 1; i >= 1; i--) {
11+
answer[i - 1] = numbers[i];
12+
}
13+
answer[numbers.length - 1] = numbers[0];
14+
}
15+
16+
return answer;
17+
}
18+
19+
console.log(solution([4, 455, 6, 4, -1, 45, 6], 'left'));

unn04012/array/cut_array.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function solution(numbers, num1, num2) {
2+
const answer = [];
3+
4+
for (let i = num1; i <= num2; i++) answer.push(numbers[i]);
5+
6+
return answer;
7+
}
8+
9+
console.log(solution([1, 2, 3, 4, 5], 1, 3));

unn04012/array/delete_min_num.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function solution(arr) {
2+
const answer = [];
3+
const minNum = Math.min(...arr);
4+
5+
for (const e of arr) {
6+
if (e === minNum) continue;
7+
answer.push(e);
8+
}
9+
return answer.length ? answer : [-1];
10+
}

0 commit comments

Comments
 (0)