小编and*_*rew的帖子

Node.js 不写入文件?

我正在尝试制作一个质数筛,它对我来说效果很好。但是,它不会将数据写入文件。它说素数被转储到一个文件中。fs.writeFile 有大小限制吗?素数数组可能会变得非常大。有人可以帮我弄这个吗?

代码:

#!/usr/bin/env node

var primes = ["2", "3"];
var num = 3;
var prime;
var fs = require("fs");

console.log("Hundreds: 2");
console.log("Hundreds: 3");


while (true) {
  prime = true;
  var times = Math.pow(num, 0.5);
  for (var i=0;i<times;i++) {
    if (num % parseInt(primes[i], 32) == 0) {
      prime = false;
      break;
    }
  }
  if (prime) {
    var place = String(num).length;
    switch (true) {
      case place <= 3:
        console.log("Hundreds: "+num);
      break;
      case place <= 5 :
        console.log("Thousands: "+num);
      break;
      case 6 …
Run Code Online (Sandbox Code Playgroud)

node.js

2
推荐指数
1
解决办法
1752
查看次数

在 Node.js 中读取第 n 行而不读取整个文件

我正在尝试使用 Node.js 在 4800 万行文件中获取特定行进行二进制搜索,但我不想将整个文件读入内存。是否有一些功能可以让我阅读 3000 万行?我正在寻找类似Python 的 linecache 模块的东西。

更新它的不同之处:我不想将整个文件读入内存。这个问题被识别为重复读取整个文件到内存。

file node.js

2
推荐指数
2
解决办法
4845
查看次数

如何使div包含一切

我在jsfiddle有一个程序,我想知道我应该让div绕过一切.绕过一切我的意思是绕过一切.(更有效的jQuery代码将不胜感激;).)这是代码:

div {
    border:2px red outset;
}
div#container {
    width:50%;
}
div.section {
    position:relative;
    width:48%;
    display:inline;
    float:left;
}
    h3 {
    display:inline;
    width:48%;
    float:left;
    margin:0.65;
    text-align:center;
} a {
    display:inline;
    width:23%;
    float:left;
    margin:0.65%;
    text-align:center;
}
Run Code Online (Sandbox Code Playgroud)

我的HTML:

<div id="container">
    <h3>Section 1</h3>

    <h3>Section 2</h3>
    <br />
    <br /> <a href="#sec1" class="hide">Hide</a><a href="#sec1" class="show">Show</a>
    <a href="#sec2" class="hide">Hide</a><a href="#sec2" class="show">Show</a>

    <div id="sec1" class="section">Some content</div>
    <br />
    <div id="sec2" class="section">Some more content</div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css

0
推荐指数
1
解决办法
451
查看次数

标签 统计

node.js ×2

css ×1

file ×1

html ×1