diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\244.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\244.js" new file mode 100644 index 0000000000000000000000000000000000000000..cd33ae57e661d3107becfa4f7ab1e02df9cdb4c1 --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\244.js" @@ -0,0 +1,19 @@ +module.exports = +//加 + function add(x, y) { + return parseInt(x) + parseInt(y); +} +//减 +function subtract(x, y) { + return parseInt(x) - parseInt(y) + +} +//乘 + function multiply(x, y) { + return parseInt(x) * parseInt(y) + +} +//除 + function divide(x, y) { + return parseInt(x) / parseInt(y) +} \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2442.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2442.js" new file mode 100644 index 0000000000000000000000000000000000000000..eaffc66eaf465fa12efec512de4896a28e34095e --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2442.js" @@ -0,0 +1,20 @@ +add: function add(x, y) { + return x + y; +} +subtract: function subtract(x, y) { + return x - y; +} +multiply:function multiply(x, y) { + return x * y; +} +divide:function divide(x, y) { + return x / y; +} + +function handle(x, y, symbol) { +if (isNaN(x) || isNaN(y)) { + throw Error("输入数值"); +} +return count[symbol](x, y); +} +module.exports.handle = handle; \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2443.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2443.js" new file mode 100644 index 0000000000000000000000000000000000000000..7cf921c72cc8f854eab2dc8b5d9e5df505a110ae --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2443.js" @@ -0,0 +1,12 @@ +let cal=require('./calculate'); +let add=(8+9); +console.log(add); + +let subtract=(8-9); +console.log(subtract); + +let multiply=(2*9); +console.log(multiply); + +let divide=(18/2); +console.log(divide); \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2444.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2444.js" new file mode 100644 index 0000000000000000000000000000000000000000..9781fbc5685d5bc8a03212d86ed4d77be6693415 --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.22\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/\345\212\240\345\207\217\344\271\230\351\231\2444.js" @@ -0,0 +1,9 @@ +let count = require('./module_count'); +try { + console.log(count.handle(9, 3, 'add')); + console.log(count.handle(6, 3, 'subtract')); + console.log(count.handle(3, 2, 'multiply')); + console.log(count.handle(20, 4, 'divide')); +} catch (error) { + console.log(error.message); +} \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/fileplay.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/fileplay.js" new file mode 100644 index 0000000000000000000000000000000000000000..896491fa2352d7209dfc414e0eda4ed30ac4cb6b --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/fileplay.js" @@ -0,0 +1,17 @@ +//写一段代码,可以指定的创建多个文件,文件名中要有序号,写入的内容可以随机 +let fs=require("fs") +let fd=[] +function create(num){ + if (isNaN(num)) { + throw new Error("输入数字") + } else { + for (let i = 1; i < num; i++) { + fd[i] = fs.openSync(`${i}.txt`, "w"); + fs.writeSync(fd[i], `${Math.random()}`); + fs.closeSync(fd[i]) + } + } +} +module.exports={ + create:create +} \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/writefile.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/writefile.js" new file mode 100644 index 0000000000000000000000000000000000000000..b5ac5e9b5fbe51365f7bc442cf64e9181846075e --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.2.24 fs\345\220\214\346\255\245\345\206\231\345\205\245\345\210\233\345\273\272\346\226\207\344\273\266/writefile.js" @@ -0,0 +1,7 @@ +//调用fs.js +let cre=require("./fileplay"); +try{ + cre.create(6) +}catch(error){ + console.log(error.message); +} \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/createFile.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/createFile.js" new file mode 100644 index 0000000000000000000000000000000000000000..e025ad1a10f4c9cff480114d0b89e2ae8685f96b --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/createFile.js" @@ -0,0 +1,26 @@ +let fs=require('fs'); + +let path='./demo'; + +//判断是否存在目录 +if(!fs.existsSync(path)) { + fs.mkdirSync(path); +} + +//循环创建100个文件 +for(let i=1;i<=100;i++){ + //文件名 + let fileName=path+'/'+i+'.txt'; + //打开文件 + let fd=fs.openSync(fileName,'a'); + //写入文件 + //生成随机数并取整数 + // function getRandom(min, max) { + // return Math.floor(Math.random() * (max - min + 1)) + min; + // } + // let num = getRandom(1, 100); + let random=Math.floor(Math.random()*10); + fs.writeSync(fd,random); + //关闭文件 + fs.closeSync(fd); +} \ No newline at end of file diff --git "a/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/sort.js" "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/sort.js" new file mode 100644 index 0000000000000000000000000000000000000000..ebc1108882fa5943ad7cffc506f3d66871883459 --- /dev/null +++ "b/\351\253\230\345\256\207/\351\253\230\345\256\2072022.3.1 nodejs\345\206\231\345\205\245\350\257\273\345\217\226/sort.js" @@ -0,0 +1,24 @@ +//模块引入 +let fs=require('fs'); + +let path='./demo'; + +for(let i=1;i<=101;i++){ + for(let j=1;j<101-i;j++){ + let filename1=path+'/'+j+'.txt'; + let filename2=path+'/'+(j+1)+'.txt'; + + + let fd1=+fs.readFileSync(filename1,{flag:'r',encoding:'utf8'}); + let fd2=+fs.readFileSync(filename2,{flag:'r',encoding:'utf8'}); + + let num1=+fd1.toString(); + let num2=+fd2.toString(); + + if(num1 > num2){ + fs.writeFileSync(filename1,num2,{flag:'w'}); + fs.writeFileSync(filename2,num1,{flag:'w'}); + + } + } +}·· \ No newline at end of file