신수용

javascript

{
"curly": true,
"eqeqeq": true,
"undef": true,
"globals": {
"jQuery": true,
"Promise" : true
},
"node": true
}
"use strict";
console.log("Hello, World");
"use strict";
function asyncTask1(cb) {
console.log("task1 start");
setTimeout(function() {
cb("task1");
}, 2000);
}
function asyncTask2(cb) {
console.log("task2 start");
setTimeout(function() {
cb("task2");
}, 1000);
}
asyncTask2(function(ret) {
console.log(ret + " done");
asyncTask1(function(ret2) {
console.log(ret2 + "done");
// 추가적인 callback이 더 생긴다면???
});
});
function promiseTask1() {
console.log("task1 start");
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('task1');
}, 2000);
});
}
function promiseTask2() {
console.log("task2 start");
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('task2');
}, 1000);
});
}
promiseTask2()
.then(function(ret) {
console.log(ret + " done");
}).then(function() {
return promiseTask1();
})
.then(function(ret) {
console.log(ret + " done");
});
"use strict";
function swap(arr, i, j) {
var t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
function bubbleSort(arr) {
var i, j;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr.length - i; j++) {
if (arr[j] > arr[j+1]) {
swap(arr, j, j+1);
}
}
}
return arr;
}
var arr1 = [6, 3, 2, 7, 8, 3, 1, 0, 9, 5];
var arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var arr3 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
console.log(bubbleSort(arr1));
console.log(bubbleSort(arr2));
console.log(bubbleSort(arr3));
\ No newline at end of file
<html>
<head>
</head>
<body>
<script type="text/javascript" src="03_sort.js">
</script>
</body>
</html>