第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 Node.js 中比較兩個(gè)文件的好方法是什么

在 Node.js 中比較兩個(gè)文件的好方法是什么

守候你守候我 2021-12-23 15:48:08
我正在嘗試構(gòu)建一個(gè)簡(jiǎn)單的自動(dòng)分級(jí)器來檢查兩個(gè) javascript 匹配文件。這是一個(gè)可能的練習(xí)示例:var http = require('http');http.createServer((req, res) => {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello World!');}).listen(8000,  () => {console.log('Node server is running..');});這是上述練習(xí)的解決方案:var http = require('http');var dt = require('./myfirstmodule');http.createServer((req, res) => {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.write("The date and time are currently: " + dt.myDateTime());  res.end('Hello World!');}).listen(8000,  () => {console.log('Node server is running..');});你知道在 Node 中檢查練習(xí)文件是否與解決方案匹配的好方法嗎?完全匹配文件可能不是一個(gè)好主意,因?yàn)樗鼈冎g可能存在空格并且仍然是一個(gè)有效的解決方案。提前致謝。
查看完整描述

1 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以使用讀取每個(gè)文件的內(nèi)容,fs.readFileSync()然后使用包字符串相似度來比較它們。


安裝字符串相似度:


npm install string-similarity --save

然后在你的代碼中:


const fs = require('fs');

const stringSimilarity = require('string-similarity');


let exercise = fs.readFileSync('path/to/file/exercise.js');

let solution = fs.readFileSync('path/to/file/solution.js');


var similarity = stringSimilarity.compareTwoStrings(exercise, solution);

console.log(similarity); //Returns a fraction between 0 and 1


查看完整回答
反對(duì) 回復(fù) 2021-12-23
  • 1 回答
  • 0 關(guān)注
  • 767 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)