我试图理解这行代码.对r [e]做什么是减去和做什么?:
r = {}
for (e of s)
r[e] = -~r[e] // What is this specific line assigning?
for (e in r)
if (r[e] == 1)
return e
return '_'
Run Code Online (Sandbox Code Playgroud)
此代码解决的问题是这个(特定行被注释):
给定一个字符串s,找到并返回其中非重复字符的第一个实例.如果没有这样的字符,则返回'_'.
除了评论之外,我理解其他行.
我正在尝试使用MongoDB创建一个简单的React博客应用程序来存储帖子,但是当我尝试将Mongoose模型导入我的NewPost组件时,webpack将无法编译.
以下是错误:
WARNING in ./node_modules/mongoose/lib/drivers/index.js
10:13-49 Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js
82:18-42 Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js
90:20-44 Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js
97:35-67 Critical dependency: the request of a dependency is an expression
ERROR in ./node_modules/mongodb/lib/gridfs/grid_store.js
Module not found: Error: Can't resolve 'fs' in 'D:\mydocs\webdev\gitprojs\ReactBlogFinal\node_modules\mongodb\lib\gridfs'
@ ./node_modules/mongodb/lib/gridfs/grid_store.js 42:7-20
@ ./node_modules/mongodb/index.js
@ ./node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js
@ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
@ …
Run Code Online (Sandbox Code Playgroud) 我是 Angular 2 的新手,我试图让它呈现一个包含其他模板/组件的视图组件。这就是我想要在 /home 路由上呈现的内容。问题:当我转到 /home 路线时,它转到一个空白页面而不是呈现我的模板。控制台中没有错误。
这是我的home.component.html:
<router-outlet></router-outlet>
<container>
<header-component></header-component>
<check-portfolio></check-portfolio>
<portfolio-carousel></portfolio-carousel>
<skill-section></skill-section>
<need-help></need-help>
</container>
Run Code Online (Sandbox Code Playgroud)
home.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的app.module.ts 的一些部分。我不确定我的app.component.html是否需要任何内容,但它是空白的:
const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
]
@NgModule({
declarations: [
AppComponent, …
Run Code Online (Sandbox Code Playgroud)