在对数组方法进行深入研究时,我决定查看Array.sort方法中涉及的步骤.看看这段代码来反转数组的顺序:
let arr = [];
for (let i = 1; i < 6; i++) {
arr.push(i);
}
arr.sort((value1, value2) => {
console.log(arr);
console.log(`Comparing ${value1} : ${value2}`);
return value2 - value1;
});
console.log(arr);Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
[1, 2, 3, 4, 5]
Comparing 1 : 2
[2, 1, 3, 4, 5]
Comparing 1 : 3
[2, 1, 1, 4, 5]
Comparing 2 : 3
[3, 2, 1, 4, 5]
Comparing 1 : 4
[3, 2, 1, 1, 5]
Comparing 2 : 4
[3, 2, …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试处理 SignalR 连接的 Angular 服务,该服务将 SignalR 的代码作为 InjectionToken。
这是提供程序文件:
// signalr-provider.ts
import { InjectionToken } from '@angular/core';
export const SIGNALR_TOKEN = new InjectionToken('signalR');
export function signalRFactory() {
return window['signalR'];
}
export const SIGNALR_PROVIDER = [ { provide: SIGNALR_TOKEN, useFactory: signalRFactory } ];
Run Code Online (Sandbox Code Playgroud)
这是服务:
// signalr-service.ts
import { Injectable, Inject } from '@angular/core';
import { SIGNALR_TOKEN } from './signalr-provider';
import { HubConnection } from '@aspnet/signalr';
import { environment } from '../../../environments/environment';
@Injectable()
export class SignalrService {
private hubConnection: HubConnection;
private baseUrl: …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,即在Entity Framework Core和Asp .NET Core中建立一个简单的多对多关系,这让我很生气.每当我尝试使用该Includes()方法返回相关集合时,我的HTTP响应就会中断.有人可以帮帮我吗?
快速演示,这是Product和Category类之间的简单关系:
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public ICollection<ProductCategory> ProductCategories { get; set; }
}
public class Category
{
public int CategoryId { get; set; }
public string Name { get; set; }
public ICollection<ProductCategory> ProductCategories { get; set; }
}
public class ProductCategory
{
public int ProductId { get; set; }
public int CategoryId { get; set; }
public Product …Run Code Online (Sandbox Code Playgroud) 在使用dotnetfiddle解决一些练习问题时,我遇到了一些非常奇怪的事情.我有一个应用数学序列的程序(每个步骤的不同计算取决于当前步骤是偶数还是奇数):
using System;
public class Program
{
public static void Main()
{
int ceiling = 1000000;
int maxMoves = 0;
int maxStart = 0;
int testNumber;
for(int i = 1; i <= ceiling; i++){
testNumber = i;
int moves = 1;
while(testNumber != 1){
if(testNumber % 2 == 0){
testNumber = testNumber / 2;
moves++;
} else {
testNumber = (3 * testNumber) + 1;
moves++;
}
}
if(moves > maxMoves){
maxMoves = moves;
maxStart = …Run Code Online (Sandbox Code Playgroud)