小编A-S*_*ani的帖子

当试图打印帕斯卡三角形时,第13次迭代打印错误的答案

我在C中编写一个脚本来打印出pascals三角形,所以我为factorial编写了一个函数,然后将变量c =变为二项式展开式,这直到第n行,它产生输出:

1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 
1 5 10 10 5 1 
1 6 15 20 15 6 1 
1 7 21 35 35 21 7 1 
1 8 28 56 70 56 28 8 1 
1 9 36 84 126 126 84 36 9 1 
1 10 45 120 210 252 210 120 45 10 1 
1 11 55 165 330 462 462 330 165 55 11 1 …
Run Code Online (Sandbox Code Playgroud)

c pascals-triangle

4
推荐指数
1
解决办法
84
查看次数

在express js中通过id删除mongodb文档

我正在为此纠结……试图通过 id 删除文档:

router.delete('/api/menu/delete/:id', function (req, res) {
  var id = req.params.id;
  db.get().collection('menu', function (err, col) {
   col.deleteOne({_id: new mongodb.ObjectID(id)});
  });
  res.json({ success: id })
});
Run Code Online (Sandbox Code Playgroud)

总是得到:

Cannot read property deleteOne of undefined
Run Code Online (Sandbox Code Playgroud)

尝试查找记录时,它按预期工作。

mongodb node.js express

4
推荐指数
1
解决办法
1万
查看次数

带有方法 GET 的 Angular HttpClient 参数不起作用

我想问你关于 get 方法的参数。我有这样的事情:

    path = 'https://example.com/api';
    const params = new HttpParams();
    params.append('http', 'angular');
    return this.http.get(path, {params: params});
Run Code Online (Sandbox Code Playgroud)

我以为我会有这样的网址:

www.example.com/api?http=angular

但实际上,当我在 chrome 的网络选项卡中检查时,请求 url 是

www.example.com/api

当我想要路径时应该怎么做: www.example.com/api?http=angular 是否可以在没有 chrome 的情况下检查使用方法的请求 url?我的意思是在使用该方法的服务中?

http typescript angular-http angular

4
推荐指数
1
解决办法
2983
查看次数

从嵌套数组到对象数组

我有这样的嵌套数组

array = [[1, 698],[32, 798],[69, 830],[95, 500]]
Run Code Online (Sandbox Code Playgroud)

我想要一个以这种格式返回结果的函数

[
    {
        id: 1,
        score: 698
    },
    {
        id: 32,
        score: 798
    },
    {
        id: 69,
        score:830
    },
  ..... the rest of the array
]
Run Code Online (Sandbox Code Playgroud)

我确实使用了for循环,但没有成功,我不知道如何处理这种情况.

for(var i = 0; i <= array.lenght ; i++){
    var obj={}
    var res = []
    res.push(array[i])
}
Run Code Online (Sandbox Code Playgroud)

html javascript

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

Angular Material mat-table未显示数据源中的更新数据

我的简单任务是将输入框中输入的文本添加到mat-table,但它没有按预期工作.数据源仅刷新一次,并且未显示第二次更新数据.

这是我的代码app.component.html

 <div class="main" fxLayout="column" fxGap="10">
   <div class="input-area">
     <mat-form-field>
        <input matInput placeholder="Type something" [(ngModel)]="currentText"> 
     </mat-form-field>
     <button mat-raised-button color="primary" style="margin-left:10px;" (click)="onAdd($event)">Add</button>
   </div>
   <div class="result-area">
      <mat-table #table [dataSource]="dataSource" class="mat-elevation-z8">
        <ng-container matColumnDef="name">
         <mat-header-cell #th *matHeaderCellDef> Name </mat-header-cell>
         <mat-cell #td *matCellDef="let element"> {{element.name}} </mat-cell>
        </ng-container>
        <mat-header-row #tr *matHeaderRowDef="displayedColumns"></mat-header-row>
        <mat-row #tr *matRowDef="let row; columns: displayedColumns;"></mat-row>
      </mat-table>
   </div>
Run Code Online (Sandbox Code Playgroud)

这是我的"app.component.ts",其中包含更新表数据源的"添加"事件.

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  currentText: string= "";
  displayedColumns = ['name'];
  data: Data[] = [];
  dataSource: Data[];

  constructor(){} …
Run Code Online (Sandbox Code Playgroud)

angular-material angular

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

Android kotlin: putParcelableArrayList(ArrayList&lt;int&gt;) 和 getParcelableArrayList&lt;Int&gt;() 不起作用

我试图ArrayList<Integer>从片段传递到另一个片段,这是我的代码:

科特林代码

companion object {
    fun newInstance(categoryId: Int, brandsList: ArrayList<Int>): Fragment {
        val fragment = CategoryAllAdsFragment()
        fragment.arguments = Bundle()
        fragment.arguments!!.putInt(Constant.CATEGORY_ID, categoryId)
        fragment.arguments!!.putParcelableArrayList(Constant.BRANDS_LIST, brandsList)
        return fragment
    }
}
Run Code Online (Sandbox Code Playgroud)

但它说:

类型不匹配。

必需: java.util.ArrayList !

发现:kotlin.collections.ArrayList /* = java.util.ArrayList */

当我试图阅读它时,也是同样的事情。

科特林代码

try {
    val brandsList = arguments!!.getParcelableArrayList<Int>(Constant.BRANDS_LIST)
} catch (ex: Exception) {
    throw Exception("brand list cannot be null")
}
Run Code Online (Sandbox Code Playgroud)

它说:

类型参数不在其范围内

预期:可打包!

发现:Int

我已经测试过它Java并且它工作正常。

android arraylist parcelable kotlin

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

使用 createSpyObj 创建间谍时 callThrough 不起作用

and.callThrough当使用创建间谍对象时,似乎并没有实际运行原始实现createSpyObj。举个例子,假设我有一个 Angular 服务,它具有以下帮助器方法:

user.service.ts:

class UserService {

    getFullName(first: string, last: string): string {
         return first + ' ' + last;
    }
}
Run Code Online (Sandbox Code Playgroud)

在规范中,我使用以下方法创建了一个间谍createSpyObj

user.service.specs.ts

const userServiceSpy = jasmine.createSpyObj<UserService>('UserService', ['getFullName']);

// ....

beforeEach(() => {

    userServiceSpy.getFullName.and.callThought();
    const test = userService.getFullName('test1', 'test2');
    console.log(test);   // < = = = = = ISSUE: test is undefined! WHY ???
});
Run Code Online (Sandbox Code Playgroud)

如何使该getFullName函数按照主类中的实现运行?(我不想存根或调用假函数,但在调用时以某种方式使用主函数实现getFullName)。

我尝试用原来的函数原型覆盖函数原型:

userServiceSpy.getFullName.prototype = UserService.prototype.getFullName;
Run Code Online (Sandbox Code Playgroud)

第二次尝试:

userServiceSpy.getFullName = UserService.prototyp.getFullName; // This is a compile error. 
Run Code Online (Sandbox Code Playgroud)

javascript jasmine typescript karma-jasmine angular

4
推荐指数
1
解决办法
4066
查看次数

播放声音效果(CLICK / NAVIGATION_RIGHT)以获得按钮点击-Android

我正在尝试使用该playSoundEffect ()方法在单击按钮时播放声音效果,但是到目前为止,由于某种原因,事实证明它非常困难。

我定义了以下内容。

<ImageButton android:id="@+id/Button_flip" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="FLIP!"
android:src="@drawable/flip" android:soundEffectsEnabled="true">
</ImageButton>
Run Code Online (Sandbox Code Playgroud)

然后,

button_flip.playSoundEffect(android.view.SoundEffectConstants.CLICK);
Run Code Online (Sandbox Code Playgroud)

在onCreate()方法中调用。但是当我单击按钮时,似乎无法听到声音。我在这里想念什么?该文档没什么可继续的。

我需要在onClick()方法中定义/调用吗?

任何帮助表示赞赏。

audio android effects button

3
推荐指数
1
解决办法
9587
查看次数

我如何找到数组中的最大值?

在java中,我需要能够通过一个数组并找到最大值.我如何比较数组的元素以找到最大值?

java arrays for-loop max

3
推荐指数
3
解决办法
23万
查看次数

如何使用cin指定char指针?

所以基本上当我尝试这样做时

char* inputFileName;
cout<<  "Filename: "; cin>>*inputFileName;
Run Code Online (Sandbox Code Playgroud)

它让我输入文件名但是当我按下回车时我得到一个未处理的异常错误.有任何想法吗?

如果我尝试也编辑

char* inputFileName;
cout<<  "Filename: "; cin>>inputFileName;
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我得到一个调试断言失败.

c++

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