Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Moonjonghoo/array/create_stars_at_intersections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function solution(line) {
var answer = [];
return answer;
}
17 changes: 17 additions & 0 deletions Moonjonghoo/array/divisible_number_array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function solution(arr, divisor) {
var answer = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] % divisor === 0) {
answer.push(arr[i]);
}
}
if (answer.length === 0) {
answer = [-1];
}

answer.sort(function (a, b) {
return a - b;
});
Comment on lines +12 to +14
Copy link
Collaborator

@JustDevRae JustDevRae Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort를 화살표 함수가 아닌 익명 함수로 표현하신 이유가 있나요? 단순히 궁금해서 질문드려요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가끔실수가나와서 익명함수로 표현했습니다 ㅎㅎ..


return answer;
}
9 changes: 9 additions & 0 deletions Moonjonghoo/array/duplicate_number_count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function solution(array, n) {
var answer = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] === n) {
answer++;
}
}
return answer;
}
9 changes: 9 additions & 0 deletions Moonjonghoo/array/length_of_an_array_element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function solution(strlist) {
var answer = [];
for (let i = 0; i < strlist.length; i++) {
answer.push(strlist[i].length);
}
Comment on lines +3 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map 메서드를 사용하면 더 간결하게 구현하실 수 있으실 것 같아요!

return answer;
}

console.log(solution(["We", "are", "the", "world!"]));
23 changes: 23 additions & 0 deletions Moonjonghoo/array/matrix_addition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function solution(arr1, arr2) {
var answer = [];
for (let i = 0; i < arr1.length; i++) {
let minarr = [];
for (let j = 0; j < arr1[i].length; j++) {
minarr.push(arr1[i][j] + arr2[i][j]);
}
answer.push(minarr);
}
return answer;
}
console.log(
solution(
[
[1, 2],
[2, 3],
],
[
[3, 4],
[5, 6],
]
)
);
17 changes: 17 additions & 0 deletions Moonjonghoo/array/matrix_multiplication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function solution(arr1, arr2) {
const newArr = [];

for (let i = 0; i < arr1.length; i++) {
let result = [];
for (let j = 0; j < arr2[0].length; j++) {
let elem = 0;
for (let k = 0; k < arr2.length; k++) {
// arr1[0].length도 가능.
elem += arr1[i][k] * arr2[k][j];
}
result.push(elem);
}
newArr.push(result);
}
return newArr;
}
16 changes: 16 additions & 0 deletions Moonjonghoo/array/remove_smallest_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function solution(arr) {
var answer = [];
if (arr.length === 1) {
answer = [-1];
} else {
let min = Math.min(...arr);
for (let i = 0; i < arr.length; i++) {
if (arr[i] !== min) {
answer.push(arr[i]);
}
}
Comment on lines +7 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for문 부분을 filter 메서드를 사용하면 더 간결하게 작성할 수 있을 것 같아요!

}
return answer;
}

solution([4, 3, 2, 1]);
20 changes: 20 additions & 0 deletions Moonjonghoo/array/rotate_an_array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function solution(numbers, direction) {
var answer = [];
//배열내부에 위치를 변경시키는 방법
for (let i = 0; i < numbers.length; i++) {
if (direction === "right") {
let start = numbers[numbers.length - 1];
answer = numbers.slice(0, numbers.length - 1);
answer.unshift(start);
}
if (direction === "left") {
let start = numbers[0];
answer = numbers.slice(1, numbers.length);
answer.push(start);
}
}

return answer;
}
Comment on lines +4 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조건문으로도 잘 동작하는것 같은데 for문으로 조건문을 감싼 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러네요 수정하겠습니다!


console.log(solution([1, 2, 3], "right"));
7 changes: 7 additions & 0 deletions Moonjonghoo/array/slice_an_array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function solution(numbers, num1, num2) {
var answer = [];
answer = numbers.slice(num1, num2 + 1);
return answer;
}

console.log(solution([1, 2, 3, 4, 5], 1, 3));
Loading