我正在使用别人的笔记本电脑与 vscode,虽然我能够推送到我的 github 存储库,但它出现在他们的名字下,这使得我的 github 帐户看起来不活跃。
VSCode 中的集成终端如下所示:Bob's Macbook:(directory name) Bob
因此,当我推送到我的存储库时,看起来好像是在Bob对我的存储库进行提交,而实际上是我。因此,我个人资料上的“最近活动”图表看起来不像我一直在承诺,这并不理想。
我找不到在 VSCode 设置中更改用户的位置,所以我想我会将其发布在这里,以防有人遇到同样的问题。
如何将我的 github 用户名连接到 VSCode 终端?
我试图找到数字数组中的第二大数字,但最大的数字出现两次,所以我不能只是将其从数组中删除并选择新的最大数字。
array = [0, 3, 2, 5, 5](因此3是第二大值)
我有这段代码,可以显式返回 3,但它不适用于其他数组:
function getSecondLargest(nums) {
var sorted_array = nums.sort(function (a,b) {return a - b;});
var unique_sorted_array = sorted_array.filter(function(elem, index, self) {
return index === self.indexOf(elem);
})
return unique_sorted_array[unique_sorted_array.length - 2];
}
return unique_sorted_array[unique_sorted_array.length - 2];
Run Code Online (Sandbox Code Playgroud)
如果我想让它更加动态,有没有一种方法可以识别数组的最大值,然后将其与数组的每次迭代进行比较?
我在想类似的事情:
var greatestNum = sortedArray[-1]
while(greatestNum != i) do {
//check for the first number that doesn't equal greatestNum
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
我正在创建一个简单的 CRUD React 应用程序,让您可以管理产品。产品只有一个name和一个price。
在我addProduct命令成分,我的onSubmit方法可以成功登录this.nameInput.value, this.priceInput.value,但是当我改变日志this.props.onAdd我得到this.props.onAdd is not a function。
我正在学习教程,所以我确定我遗漏了一件小事,但可以在我的代码上使用另一组眼睛。
这是我的addProduct组件 - 该onSubmit方法具有this.props.onadd(...):
import React, { Component } from 'react';
class AddProduct extends Component {
constructor(props) {
super(props);
this.onSubmit = this.onSubmit.bind(this);
}
onSubmit(event) {
event.preventDefault();
this.props.onAdd(this.nameInput.value, this.priceInput.value);
}
render() {
return (
<form onSubmit={this.onSubmit}>
<h3>Add Product</h3>
<input placeholder="Name" ref={nameInput => this.nameInput = nameInput}/>
<input placeholder="Price" ref={priceInput => this.priceInput = …Run Code Online (Sandbox Code Playgroud)