--- .vscode/launch.json
+++ .vscode/launch.json
... | ... | @@ -1,15 +1,0 @@ |
1 |
-{ |
|
2 |
- // Use IntelliSense to learn about possible attributes. |
|
3 |
- // Hover to view descriptions of existing attributes. |
|
4 |
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
|
5 |
- "version": "0.2.0", |
|
6 |
- "configurations": [ |
|
7 |
- { |
|
8 |
- "type": "pwa-chrome", |
|
9 |
- "request": "launch", |
|
10 |
- "name": "Launch Chrome against localhost", |
|
11 |
- "url": "http://localhost:8080", |
|
12 |
- "webRoot": "${workspaceFolder}" |
|
13 |
- } |
|
14 |
- ] |
|
15 |
-}(No newline at end of file) |
--- al01/2.js
+++ al01/2.js
... | ... | @@ -1,13 +1,16 @@ |
1 | 1 |
//길이가 다른 3개의 막대로 삼각형을 만들 수 있는지 여부 |
2 | 2 |
|
3 | 3 |
function triangle(a, b, c){ |
4 |
- let result; |
|
4 |
+ let result = "NO"; |
|
5 | 5 |
|
6 |
- if(a+b>c && a+c>b && b+c>a){ |
|
7 |
- result = "YES"; |
|
8 |
- }else{ |
|
9 |
- result ="NO"; |
|
6 |
+ if(a>0 && b>0 && c>0){ |
|
7 |
+ if(a+b>c && a+c>b && b+c>a){ |
|
8 |
+ result = "YES"; |
|
9 |
+ } |
|
10 | 10 |
} |
11 |
+ |
|
12 |
+ |
|
13 |
+ |
|
11 | 14 |
|
12 | 15 |
return result; |
13 | 16 |
} |
--- al01/3.js
+++ al01/3.js
... | ... | @@ -1,7 +1,16 @@ |
1 | 1 |
//1개씩 줄 때 학생 N명이 있을 때 필요한 연필의 다스 수 |
2 | 2 |
|
3 |
+// function das(a){ |
|
4 |
+// return Math.ceil(a/12); |
|
5 |
+// } |
|
6 |
+ |
|
3 | 7 |
function das(a){ |
4 |
- return Math.ceil(a/12); |
|
8 |
+ let answer; |
|
9 |
+ |
|
10 |
+ // answer = Math.ceil(a/12); |
|
11 |
+ answer = (a%12===0)?a/12:parseInt(a/12)+1; |
|
12 |
+ |
|
13 |
+ return answer; |
|
5 | 14 |
} |
6 | 15 |
|
7 | 16 |
console.log(das(25)); |
--- al01/4.js
+++ al01/4.js
... | ... | @@ -2,8 +2,14 @@ |
2 | 2 |
|
3 | 3 |
function sum(a){ |
4 | 4 |
let sum = 0; |
5 |
- for(let i = 1; i <= a; i++){ |
|
6 |
- sum = sum + i; |
|
5 |
+ // for(let i = 1; i <= a; i++){ |
|
6 |
+ // sum += i; |
|
7 |
+ // } |
|
8 |
+ |
|
9 |
+ let i = 1; |
|
10 |
+ while(i<=a){ |
|
11 |
+ sum += i; |
|
12 |
+ i++; |
|
7 | 13 |
} |
8 | 14 |
|
9 | 15 |
return sum; |
... | ... | @@ -11,4 +17,5 @@ |
11 | 17 |
} |
12 | 18 |
|
13 | 19 |
console.log(sum(6)); |
14 |
-console.log(sum(10));(No newline at end of file) |
|
20 |
+console.log(sum(10)); |
|
21 |
+console.log(sum(100));(No newline at end of file) |
--- al01/5.js
+++ al01/5.js
... | ... | @@ -1,15 +1,19 @@ |
1 | 1 |
//7개의 수 중 가장 작은 것 |
2 | 2 |
|
3 |
-function min(a, b, c, d, e, f, g){ |
|
4 |
- let arr = [a, b, c, d, e, f, g]; |
|
5 |
- let max = arr[0]; |
|
3 |
+function min(arr){ |
|
6 | 4 |
let min = arr[0]; |
7 |
- for(let i = 1; i<=7; i++){ |
|
8 |
- if(min>arr[i]){ |
|
9 |
- min = arr[i]; |
|
10 |
- } |
|
5 |
+ |
|
6 |
+ for(let i = 1; i<=arr.length; i++){ |
|
7 |
+ //else-if |
|
8 |
+ // if(min>arr[i]){ |
|
9 |
+ // min = arr[i]; |
|
10 |
+ // } |
|
11 |
+ |
|
12 |
+ //삼항연산자 |
|
13 |
+ min = min>arr[i] ? min=arr[i] : min; |
|
14 |
+ |
|
11 | 15 |
} |
12 |
- console.log(min); |
|
16 |
+ return min; |
|
13 | 17 |
} |
14 | 18 |
|
15 |
-min(1, 3, 7, 11, 2, 15, 17);(No newline at end of file) |
|
19 |
+console.log(min([1, 3, 7, 11, 2, 15, -20]));(No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?