小编T.J*_*der的帖子

新日期(新日期().getTime() - 25*24*60*60*1000)有意想不到的日期

我想生成一个日期列表,但发现日期错误从 - 25*24*60*60*1000开始

我当地的日期是2016-07-17.我有

2016-07-17
2016-07-16
2016-07-15
...
2016-06-23
2016-08-11

我不知道2016-08-11它来自哪里.我打破了25到24和-1,如下(xxxyyy),然后我得到了正确的日期2016-06-22.

为什么xxx工作但不工作yyy

Date xxx = new Date(new Date().getTime()-24 * 24 * 60 * 60 * 1000 -1 * 24 * 60 * 60 * 1000);
Date yyy = new Date(new Date().getTime()-25 * 24 * 60 * 60 * 1000);
Run Code Online (Sandbox Code Playgroud)

这是我的代码:从i = 25开始,日期错误

for (int i=0; i<240;i++) {
    Date dt = new Date(new Date().getTime() - i * 24 * …
Run Code Online (Sandbox Code Playgroud)

java android

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

在html/javascript中长时间运行的代码

我需要在按钮单击时在浏览器中运行算法.在javascript中对它进行编码非常复杂,而且速度非常慢.有没有推荐的架构呢?理想情况下,我想用C++或Python编写代码,但我想在按钮点击时无法在浏览器中运行它.那么,我的下一个最佳选择是什么?

我不能让它在服务器端运行,因为页面上会有1000次点击,这将导致来回过多的通信.

javascript web

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

jQuery气泡在表上排序

我有这张桌子,上面有一排数字。现在,我想创建一个jQuery函数,该函数将th在单击该表后对其进行排序,而我想使用Bubble Sort来实现。到目前为止,这是我所做的:

var elements_ar = $(this).parent().parent().siblings('tbody').children('tr').toArray();
for (var i = 0; i < elements_ar.length - 1; i++) {
    for (var j = 0; j < elements_ar.length - i - 1; j++) {
        var element = elements_ar[j],
            next_element = elements_ar[j + 1],
            popularity = $(element).children('td:eq(3)').text(),
            next = $(next_element).children('td:eq(3)').text();
        if (popularity > next) {
            $(element).before(next_element);
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

现在,这是正常的,但并不完美。在此完整的工作示例中,您可以看到有些行不在应有的位置:

var elements_ar = $(this).parent().parent().siblings('tbody').children('tr').toArray();
for (var i = 0; i < elements_ar.length - 1; i++) {
    for (var j = 0; …
Run Code Online (Sandbox Code Playgroud)

javascript sorting algorithm jquery

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

TSLint 烦人的消息

在我的 angular 组件上,我使用了来自 RxJs 的两种方法,debounceTime()以及distinctUntilChanged()

import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';

import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';

@Component({
  selector: 'app-form4th',
  templateUrl: './form4th.component.html',
})
export class Form4thComponent implements OnInit {
  searchField: FormControl;
  searches: string[] = [];

  constructor() { }

  ngOnInit() {
    this.searchField = new FormControl();
    this.searchField
        .valueChanges
        .debounceTime(400)
        .distinctUntilChanged()
        .subscribe(term => {
          this.searches.push(term);
        });
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序工作正常,在执行(构建)ie 时没有错误甚至没有警告消息ng serve,并且在浏览器上运行应用程序按预期工作,并且在浏览器控制台上也没有错误消息或警告。

但是,我的 vscode 上有一条奇怪的 TSLint 消息说:

[ts] Property …

javascript rxjs typescript tslint angular

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

通过外类调用内部类的方法

我知道要实例化一个成员内部类,你有两个不同的构造函数:

第一:

Outer out = new Outer();
Outer.Inner in = out.new Inner();
Run Code Online (Sandbox Code Playgroud)

第二:

Outer.Inner in = new Outer().new Inner();
Run Code Online (Sandbox Code Playgroud)

现在,我不知道为什么这段代码会编译:

public class Outer {

    private String greeting="Hi";

    protected class Inner {
        public int repeat=3;

        public void go() {
            for (int i =0; i<repeat; i++) {
                System.out.println(greeting);
            }
        }
    }

    public void callInner() {
        Inner in = new Inner(); //in my opinion the correct constructor is Outer.Inner in = new Inner()
        in.go();
    }

    public static void main(String[] args) {
        Outer out …
Run Code Online (Sandbox Code Playgroud)

java constructor inner-classes

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

How do I create a Blob in Node.js?

I have tried to create a Blob in Node.js. First just this:

var b = new Blob(['hi', 'constructing', 'a', 'blob']);
Run Code Online (Sandbox Code Playgroud)

This fails with ReferenceError: Blob is not defined

然后,我尝试使用该blob模块(两行代码来自该模块的示例,请参阅https://www.npmjs.com/package/blob):

var Blob = require('blob');
var b = new Blob(['hi', 'constructing', 'a', 'blob']);
Run Code Online (Sandbox Code Playgroud)

这失败了 TypeError: Blob is not a constructor

我该怎么做?

javascript blob node.js

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

`for` 循环 vs `.map` 来迭代数组

为什么在 React 中使用循环.map比使用for循环更好?

我正在开发一个项目,其中所有数组都使用for循环进行迭代,但我相信这是更好的好做法,.map因为它创建了数组的副本,据我所知,这是更好的做法,但我找不到一个特定的原因。

javascript reactjs

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

"Uncaught TypeError: function is not iterable" 在 [] 中使用 ...,但在 {} 中它有效......?

考虑这个简单的例子:

const someFunction = () => [1, 2, 3];
Run Code Online (Sandbox Code Playgroud)

现在

const myArr = [...someFunction];
Run Code Online (Sandbox Code Playgroud)

给出了一个运行时错误,这是可以理解的,因为函数是不可迭代的。所以

const myArr = [...someFunction()];
Run Code Online (Sandbox Code Playgroud)

是正确的实现。

然而,

const myObj = {...someFunction};
Run Code Online (Sandbox Code Playgroud)

导致{}并且不会导致相同的错误。

请帮助我理解这种行为以及为什么最后一种情况不会导致相同的错误。

javascript iterable function ecmascript-6

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

JavaScript:数组中的最大值

如果它是数组的第一个 (arr[0])最后一个索引 (arr[arr.length-1]),该函数只返回最大的数。如何修复逻辑错误?

function isGreater(arr) {
 let a = arr[0];
 for (let i = 0; i < arr.length; i++) {
  var isGreat = (a < arr[i]) ? arr[i] : a;
 }
 return isGreat;
}
console.log(isGreater([7, 9, 10000, 11, 25, 20]));
// output=> 20, expected output 10000
console.log(isGreater([7, 11, 25, 2]));
// output=> 7, expected output 25
Run Code Online (Sandbox Code Playgroud)

javascript arrays logic

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

如何将元组联合转换为对象类型

我有一个类型InputData,要么是要么string是元组。我想将其转换为对象。

type InputType = File | string | boolean;
type InputData = string | [string, InputType]

type test = "username" | "password" | ["isAbove18", boolean] | ["photo", File];
Run Code Online (Sandbox Code Playgroud)

在上面的类型中,只有string(给出了输入字段的名称)它的类型应该设置为string. 我有通用类型

type AddDefaultValues<Data extends InputData> = Data extends string ? [Data, string] : Data 
//AddDefaultValues<test> = ["username", string]| ["password", string] | ["isAbove18", boolean] | ["photo", File]
Run Code Online (Sandbox Code Playgroud)

现在我的要求是将上面的类型映射到如下所示的对象。

{username: string, password: string, isAbove18: boolean, photo: File}
Run Code Online (Sandbox Code Playgroud)

我尝试了很长时间,但什么也做不了。请帮我解决这个问题...

javascript typescript

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