倒计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="msg"></div>
<script>
function showTimes() {
let last_times = new Date("2025-06-30").getTime();
let date = new Date();
let tiems = last_times - date.getTime();
let day = tiems / 1000 / 60 / 60 / 24;
let h = day % 1 * 24;
let m = h % 1 * 60;
let s = m % 1 * 60;
document.getElementById("msg").innerHTML = "距离毕业还有" +
Math.floor(day) + "天:" + Math.floor(h) + "时:" + Math.floor(m)+"分:" + Math.floor(s) + "秒"
}
setInterval(showTimes,1000)
</script>
</body>
</html>
冒泡排序
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
function bubbleSort(arr) {
const len = arr.length
for(let i = 0; i < len - 1; i++) {
for(let j = 0; j < len -1 - i; j++) {
if(arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
}
}
}
return arr
}
const nums = [6, 5, 4, 7, 8]
console.log(bubbleSort(nums))
</script>
</body>
</html>
选择排序
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
function selectionSort(arr) {
const len = arr.length
for(let i = 0; i < len - 1; i++) {
let minIndex = i
for(let j = i + 1; j < len; j++) {
if(arr[j] < arr[minIndex]) {
minIndex = j
}
}
[arr[i], arr[minIndex]] = [arr[minIndex], arr[i]]
}
return arr
}
const nums = [6, 5, 4, 7, 8]
console.log(selectionSort(nums))
</script>
</body>
</html>
插入排序
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
function insertionSort(arr) {
const len = arr.length
for (let i = 1; i < len; i++) {
let current = arr[i]
let j = i - 1;
while (j >= 0 && arr[j] > current) {
arr[j + 1] = arr[j]
j--
}
arr[j + 1] = current
}
return arr
}
const nums = [6, 5, 4, 7, 8]
console.log(insertionSort(nums))
</script>
</body>
</html>