我正在尝试制作一个质数筛,它对我来说效果很好。但是,它不会将数据写入文件。它说素数被转储到一个文件中。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 在 4800 万行文件中获取特定行进行二进制搜索,但我不想将整个文件读入内存。是否有一些功能可以让我阅读 3000 万行?我正在寻找类似Python 的 linecache 模块的东西。
更新它的不同之处:我不想将整个文件读入内存。这个问题被识别为重复读取整个文件到内存。
我在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)