From cbbcde81276276fa3a4507d8e57537e5e5c193bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=AE=87?= <1310364462@qq.com> Date: Tue, 1 Mar 2022 11:48:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fileplay.js" | 17 ++++++++++++++++ .../writefile.js" | 7 +++++++ ...40\345\207\217\344\271\230\351\231\244.js" | 19 ++++++++++++++++++ ...0\345\207\217\344\271\230\351\231\2442.js" | 20 +++++++++++++++++++ ...0\345\207\217\344\271\230\351\231\2443.js" | 12 +++++++++++ ...0\345\207\217\344\271\230\351\231\2444.js" | 9 +++++++++ 6 files changed, 84 insertions(+) create mode 100644 "\351\253\230\345\256\207/2022.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" create mode 100644 "\351\253\230\345\256\207/2022.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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" diff --git "a/\351\253\230\345\256\207/2022.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/2022.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 0000000..896491f --- /dev/null +++ "b/\351\253\230\345\256\207/2022.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/2022.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/2022.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 0000000..b5ac5e9 --- /dev/null +++ "b/\351\253\230\345\256\207/2022.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.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 0000000..cd33ae5 --- /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 0000000..eaffc66 --- /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 0000000..7cf921c --- /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 0000000..9781fbc --- /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 -- Gitee From 375d69fe3b63e596c3a4a8e225e1fae9b5214ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=AE=87?= <1310364462@qq.com> Date: Tue, 1 Mar 2022 17:30:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\345\207\217\344\271\230\351\231\244.js" | 0 ...0\345\207\217\344\271\230\351\231\2442.js" | 0 ...0\345\207\217\344\271\230\351\231\2443.js" | 0 ...0\345\207\217\344\271\230\351\231\2444.js" | 0 .../fileplay.js" | 0 .../writefile.js" | 0 .../createFile.js" | 26 +++++++++++++++++++ .../sort.js" | 24 +++++++++++++++++ 8 files changed, 50 insertions(+) rename "\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" => "\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" (100%) rename "\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" => "\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" (100%) rename "\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" => "\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" (100%) rename "\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" => "\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" (100%) rename "\351\253\230\345\256\207/2022.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" => "\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" (100%) rename "\351\253\230\345\256\207/2022.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" => "\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" (100%) create mode 100644 "\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" create mode 100644 "\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" 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" similarity index 100% rename from "\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" rename to "\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" 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" similarity index 100% rename from "\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" rename to "\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" 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" similarity index 100% rename from "\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" rename to "\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" 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" similarity index 100% rename from "\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" rename to "\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" diff --git "a/\351\253\230\345\256\207/2022.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" similarity index 100% rename from "\351\253\230\345\256\207/2022.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" rename to "\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" diff --git "a/\351\253\230\345\256\207/2022.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" similarity index 100% rename from "\351\253\230\345\256\207/2022.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" rename to "\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" 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 0000000..e025ad1 --- /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 0000000..ebc1108 --- /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 -- Gitee