小编Alu*_*dad的帖子

在随机数组中查找最小值和最大值

处理需要我输入一些函数的赋值(查找数组中随机数的最大值/最小值,总和和平均值),我已经设法完成所有这些但是对于最小值我得到了一个值-2145379808.我不确定我搞砸了哪里,我很感激你的帮助.代码到目前为止:

#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;


int main(int argc, char** argv) {
    {
        cout << "Enter array size " << endl;
    }
    float avg;
    float sum;
    int size;
    cin >> size;
    int array[size]; 
    int max = array [0];
    int min = array [0];
    srand((unsigned)time(NULL));
    for (int i = 1; i < size + 1; i++)
    {
        array[i] = 1+rand()%100 ;
        sum += array[i];
        cout << "number " << i << " = "<< array[i] << endl; …
Run Code Online (Sandbox Code Playgroud)

c++ arrays max min

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

如何撰写验证以检查两个字段中的一个是否为空?

所以,在myForm中,有2个字段名称和电子邮件,我想添加验证以检查用户是否输入其中一个,它将通过验证; 如果两个字段都为空或空,则失败.

如何组合这样的验证器来满足我的场景?

<form [formGroup]="myForm" novalidate (ngSubmit)="submit(myForm.value)">
<div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-8">
        <div class="card">
            <div class="card-header my-contact-info">
                My Contact Info
            </div>
            <div class="card-block">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>Name:</label>
                            <small class="alert" *ngIf="!myForm.controls['name'].valid && myForm.controls['name'].touched">This field is required.</small>
                            <input type="text" class="form-control" formControlName="name">
                        </div>
                        <div class="form-group">
                            <label>Email:</label>
                            <small class="alert" *ngIf="!myForm.controls['email'].valid && myForm.controls['email'].touched">This field is required. Please input a valid email.</small>
                            <input type="text" class="form-control" formControlName="email">
                        </div>
                    </div>
                    <div class="col-md-6">

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

    buildForm(): void {
    this.myForm = this._fb.group({ …
Run Code Online (Sandbox Code Playgroud)

angular angular4-forms

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

如何使用 Express 和 TypeScript 正确共享上下文

我想使用 Express 和 TypeScript 向所有请求处理程序公开一个值。我希望能够从中间件(或其他方式)“注入”这个值,重点是应该很容易模拟它,以防万一我需要。

我想出了这个解决方案:

// The context type, I'd like to be able to inject this using the middleware below. 
// In a real scenario think of this like a database connection, etc.
type RequestContext = {
  foo: string
}

// The type enriching the Request type with the context field
type HasContext = {
  context: RequestContext
}

// Middleware attaching the context to the request
const contextMiddleware =
  (context: RequestContext) => 
  (req: Request & Partial<HasContext>, _res: Response, …
Run Code Online (Sandbox Code Playgroud)

javascript dependency-injection node.js express typescript

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

如何将现有对象中的值动态添加到新对象?

目前,我有一个空的新对象,我想将值从现有对象填充到新对象,因为我想使用现有对象中只有有限属性的对象(例如,我只想要四个属性而不是八个属性)。

到目前为止,这是我进行映射的方式:

  const newObject: any = {};
  for (let i = 0; i < this.PRODUCT_DATA.length; i++) {

       newObject._productSkuKey = this.PRODUCT_DATA[i]._productSkuKey;
       newObject._storeKey = this.itemPriceForm.get('location').value;
       newObject._price = this.PRODUCT_DATA[i]._price;
       newObject._status = this.PRODUCT_DATA[i]._isActive;
       this.updatedProducts.push(newObject);
    }
Run Code Online (Sandbox Code Playgroud)

到目前为止,它看起来是将现有对象的值存储到 newObject。但是,它只保存最后一个对象的值,而不是与对象不同的值。如何解决此问题以保存所有值(不仅仅是数组中每个对象的最后一个值)?

javascript

0
推荐指数
1
解决办法
44
查看次数

无法在 Windows 上运行 scala

我有最新的Intelliji Idea并且已经安装了 Scala 插件。如果需要Java版本:当我在终端中
java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
写入时,它说scalascala not recognized

  1. 我只是创建test.scala,但无法运行它(运行标签无法)。这是正确的方法吗?
  2. 我创建了一个项目,选择了sbt(我仍然了解它是什么以及为什么我已经/需要选择它)。出现了Scala REPL,但我认为这不是我想要的。
  3. 我可以只运行Scala类似文件的Java文件并在 IDEA 的终端中获得结果吗?
  4. 据我了解,Scala喜欢sbtJava? PS 作为一个非常新手,我在开始之前是否遗漏了一些重要的东西。Maven/Gradle
    Scala

windows scala intellij-idea

0
推荐指数
1
解决办法
235
查看次数