From ea225a8cf8666a8cf682baad51d65c3f2538a915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=85=8B=E7=BF=94?= <1574148200@qq.com> Date: Thu, 3 Mar 2022 09:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../countModule.js" | 25 +++++++++++ .../homework.js" | 9 ++++ .../result.js" | 13 ++++++ .../rule.js" | 18 ++++++++ ...14\346\254\241\347\255\224\345\244\215.js" | 43 +++++++++++++++++++ ...33\346\254\241\347\255\224\345\244\215.js" | 22 ++++++++++ 6 files changed, 130 insertions(+) create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/countModule.js" create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/homework.js" create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/result.js" create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/rule.js" create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\344\272\214\346\254\241\347\255\224\345\244\215.js" create mode 100644 "\346\235\250\345\205\213\347\277\224/\347\254\254\345\233\233\346\254\241\347\255\224\345\244\215.js" diff --git "a/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/countModule.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/countModule.js" new file mode 100644 index 0000000..5746e45 --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/countModule.js" @@ -0,0 +1,25 @@ +var count = { + + add: function(x, y) { + return x + y; + }, + subtract: function(x, y) { + return x - y; + }, + multiply: function(x, y) { + return x * y; + }, + divide: function(x, y) { + return x / y; + } + +} + +function handle(x, y, Symbol) { + if (isNaN(x) || isNaN(y)) { + throw new Error("请输入数值!"); + } + return count[Symbol](x, y); +} + +module.exports.handle = handle; diff --git "a/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/homework.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/homework.js" new file mode 100644 index 0000000..17f16d6 --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/homework.js" @@ -0,0 +1,9 @@ +let count = require('./countModule'); +try { + console.log(count.handle(2, 3, 'add')); + console.log(count.handle(6, 4, 'subtract')); + console.log(count.handle(1, 5, 'multiply')); + console.log(count.handle(30, 6, 'divide')); +} catch (error) { + console.log(error.message); +} diff --git "a/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/result.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/result.js" new file mode 100644 index 0000000..169d0e5 --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/result.js" @@ -0,0 +1,13 @@ +let result =require('./rule'); + +let add =(3+2); +console.log(add); + +let substract =(8-4); +console.log(substract); + +let multiply =(4*3); +console.log(multiply); + +let divide =(9/3); +console.log(divide); \ No newline at end of file diff --git "a/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/rule.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/rule.js" new file mode 100644 index 0000000..77aa5b9 --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\270\200\346\254\241\347\255\224\345\244\215/rule.js" @@ -0,0 +1,18 @@ +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/\346\235\250\345\205\213\347\277\224/\347\254\254\344\272\214\346\254\241\347\255\224\345\244\215.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\272\214\346\254\241\347\255\224\345\244\215.js" new file mode 100644 index 0000000..e18613d --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\344\272\214\346\254\241\347\255\224\345\244\215.js" @@ -0,0 +1,43 @@ +//- 写一段代码,可以指定的创业多个文件,文件名中要有序号,写入的内容可以随机 + +let fs = require("fs"); + +let createFile = { + + createPath: function(dir) { //创建文件夹 + //判断文件夹是否存在 + if (fs.existSync(dir()) { + return; + }) + fs.mkdirSync(dir); + }, + + + createContent: function(num) { //创建内容 + + return num + ''; + }, + + + createFile: function(filePath, content) { //写入文件与内容 + //flags w 可写 + console.log(filePath); + let fd = fs.openSync(filePath, 'w'); + fs.writeSync(fd, content); + fs.closeSync(fd); + + }, + + handle: function(num, dir) { + //目录不存在则创建 + this.createPath(dir); + //循环的创建文件与内容 + for (let i = 1; i < num; i++) { + let fileName = dir + '/' + i + '.txt'; + let content = this.createContent(i); + this.createFile = (fileName, content); + } + } +} + +createFile.handle(5,'./homework2'); \ No newline at end of file diff --git "a/\346\235\250\345\205\213\347\277\224/\347\254\254\345\233\233\346\254\241\347\255\224\345\244\215.js" "b/\346\235\250\345\205\213\347\277\224/\347\254\254\345\233\233\346\254\241\347\255\224\345\244\215.js" new file mode 100644 index 0000000..edfa111 --- /dev/null +++ "b/\346\235\250\345\205\213\347\277\224/\347\254\254\345\233\233\346\254\241\347\255\224\345\244\215.js" @@ -0,0 +1,22 @@ +// 1.先创建100个文件,文件内容自便,创建完以后呢,读取每一个文件,并且把每一个文件的内容拼接起来 + +// 2.先创建100个文件,随机写入数字,可以是整数,也可以是浮点,把最大值和最小值都取出来(可以不交.进阶题!) + +let fs = require("fs"); + +for (let i = 0; i < 100; i++) { + let fileName = 'demo' + i + '.txt'; + fs.writeFileSync(fileName, Math.round(Math.random() * 100)); +} + +let totalStr = ''; // 1 +//let arr = []; // 2 + +for (let j = 0; j < 100; j++) { + let fileName = 'demo' + j + '.txt'; + let bf = fs.readFileSync(fileName); + totalStr = totalStr + bf.toString(); + //arrs.push(bf.toString()); // 2 +} +console.log(totalStr); // 1 +//console.log(arr.join('')); // 2 -- Gitee