신수용

javascript

1 +{
2 + "curly": true,
3 + "eqeqeq": true,
4 + "undef": true,
5 + "globals": {
6 + "jQuery": true,
7 + "Promise" : true
8 + },
9 + "node": true
10 +}
1 +"use strict";
2 +
3 +console.log("Hello, World");
1 +"use strict";
2 +
3 +function asyncTask1(cb) {
4 + console.log("task1 start");
5 + setTimeout(function() {
6 + cb("task1");
7 + }, 2000);
8 +}
9 +
10 +function asyncTask2(cb) {
11 + console.log("task2 start");
12 + setTimeout(function() {
13 + cb("task2");
14 + }, 1000);
15 +}
16 +
17 +asyncTask2(function(ret) {
18 + console.log(ret + " done");
19 + asyncTask1(function(ret2) {
20 + console.log(ret2 + "done");
21 + // 추가적인 callback이 더 생긴다면???
22 + });
23 +});
24 +
25 +function promiseTask1() {
26 + console.log("task1 start");
27 + return new Promise(function(resolve, reject) {
28 + setTimeout(function() {
29 + resolve('task1');
30 + }, 2000);
31 + });
32 +}
33 +
34 +function promiseTask2() {
35 + console.log("task2 start");
36 + return new Promise(function(resolve, reject) {
37 + setTimeout(function() {
38 + resolve('task2');
39 + }, 1000);
40 + });
41 +}
42 +
43 +promiseTask2()
44 +.then(function(ret) {
45 + console.log(ret + " done");
46 +}).then(function() {
47 + return promiseTask1();
48 +})
49 +.then(function(ret) {
50 + console.log(ret + " done");
51 +});
1 +"use strict";
2 +
3 +function swap(arr, i, j) {
4 + var t = arr[i];
5 + arr[i] = arr[j];
6 + arr[j] = t;
7 +}
8 +
9 +function bubbleSort(arr) {
10 + var i, j;
11 + for (i = 0; i < arr.length; i++) {
12 + for (j = 0; j < arr.length - i; j++) {
13 + if (arr[j] > arr[j+1]) {
14 + swap(arr, j, j+1);
15 + }
16 + }
17 + }
18 + return arr;
19 +}
20 +
21 +var arr1 = [6, 3, 2, 7, 8, 3, 1, 0, 9, 5];
22 +var arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
23 +var arr3 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
24 +
25 +console.log(bubbleSort(arr1));
26 +console.log(bubbleSort(arr2));
27 +console.log(bubbleSort(arr3));
...\ No newline at end of file ...\ No newline at end of file
1 +<html>
2 +<head>
3 +</head>
4 +
5 +<body>
6 +
7 +<script type="text/javascript" src="03_sort.js">
8 +</script>
9 +
10 +</body>
11 +
12 +</html>