我有这个数组:
var arr = [5, 3, 2, 8, 1, 4];
Run Code Online (Sandbox Code Playgroud)
我正在尝试排序奇数值的元素,所以我想要这个
输出:
[1, 3, 2, 8, 5, 4]
Run Code Online (Sandbox Code Playgroud)
如你所见,偶数元素不会改变它们的位置.谁能告诉我我错过了什么?这是我的代码:
function myFunction(array) {
var oddElements = array.reduce((arr, val, index) => {
if (val % 2 !== 0){
arr.push(val);
}
return arr.sort();
}, []);
return oddElements;
}
console.log(myFunction([5, 3, 2, 8, 1, 4]));Run Code Online (Sandbox Code Playgroud)
我知道我可以使用slice将元素添加到数组中,但我仍然坚持如何获取索引并将元素放入数组中.
我已经搜索了几个小时,但仍然找不到我要找的东西。基本上,在我的Angular 6 应用程序中运行 ng serve 时,我在控制台中收到此错误:
GET http://local.mywebsitesecure.com/sockjs-node/info?t=1540568455931 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
根据我的研究,解决方案可能只是更新
webpack.config.js
但是,我在我的项目中找不到 webpack.config.js。他们还说要做:
“ng弹出”
创建一个 webpack,但它似乎不起作用。
解决方案:我可以通过运行它来让它工作(它确实有效!):
ng serve --public-host= http://localhost:4200
但是我希望能够在我的应用程序的某个地方设置它,这样我就只能做
服务
有谁知道如何解决此问题并消除此错误(sockjs-node/info)。非常感谢!
我对此做了一些研究,但仍然无法找到一个好的解决方案.我在ExtJS 4.1中编写了我的应用程序,当我在iPod上运行它时默认禁用拖动功能(这是我想要的),但如果我在ExtJS 6.2中编写相同的应用程序,所有窗口都可以拖动,这会导致可见性问题该应用程序.话虽如此,有没有人知道如何在使用平板电脑(iPod,iPad等)时禁用窗口拖动?我正在使用ExtJS 6.2
这是我的工作代码,适用于单个窗口,但我想要一个通用的解决方案,将阻止所有窗口被拖动.
var win = Ext.create('Ext.Window', {
title: "My Window",
width: 500,
modal: true,
layout: 'fit',
items: form,
buttons: [{
text: 'Close',
handler: function() {
win.hide();
}
}]
});
win.show();
if(Ext.os.deviceType === 'Tablet') {
win.dd.disable();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用父组件和子组件。子组件具有输入字段,并将用户输入的值发送给父组件,如下所示:
<parent-component (sendInputValue)="getInputValue($event)"><parent-component>
Run Code Online (Sandbox Code Playgroud)
现在在父组件中我有这个:
getInputField(data){
console.log(data); // this prints the data (Example: abc)
// then here I'm just executing the API call ONLY if data length is 3
if(data.length === 3){
this.myService.getDataFromService(data).subscribe(rs=>console.log(rs));
}
}
Run Code Online (Sandbox Code Playgroud)
现在让我们说发生了这种情况:
那么,如果输入数据是 3 个字符,并且如果用户输入更多字符,则如何始终执行 API 调用,并且如果他删除字符并返回前 3 个字符,则不会发生任何事情,因为 API 已经发生了?非常感谢!
我想打印时区缩写,例如:IST、UTC、PST、MST、CST、EST 等...
我正在将代码从 momentJS 迁移到 date-fns 并遇到以下问题。当我使用 momentJS 时,一切都按预期工作。例如,下面的代码将打印“ IST ”
const timeZone = 'Asia/Calcutta';
moment.tz(new Date(), timeZone).format('z'); // IST
Run Code Online (Sandbox Code Playgroud)
现在,我使用date-fns 的代码可以工作,但不能完全工作,因为它打印“印度标准时间”,而我只想打印IST。
format(parisDate, 'zzzz', { timeZone: 'Asia/Calcutta', locale: enGB }); // India Standard Time
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我错过了什么或做错了什么?这是我的代码的现场演示:date-fns DEMO
我正在使用多个面板,我添加了扩展/折叠它们的功能.我的问题是,当我展开它们时,我会看到所有面板中的一个丑陋的腐败文本.有谁知道如何解决这个问题?这是我的工作代码: PLUNKER
<p-panel header="Panel 1" [toggleable]="true" [collapsed]="collapsed" [style]="{'margin-bottom':'20px'}">
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
kind and benevolent …Run Code Online (Sandbox Code Playgroud) 我正在研究这个简单的java递归问题,给出以下指示:
计算黄金比例.
给定两个数字a和b,其中a> b> 0,比率为b/a.
我已经完成了一些代码,但我仍然坚持让递归正常工作.这是我的代码:
public class MyTesting {
public static void main(String[] args) {
System.out.println(ratio(8 , 4));
}
public static double ratio(int a, int b) {
int goldelRatio = 0;
if(a > b && b > 0){
return goldelRatio = a / b;
}
return goldelRatio;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将数组的值从 Laravel 中的一个方法传递到另一个方法。基本上我有一个名为orderingSubmission的方法,它从 Ajax POST 执行接收一个数组(该部分工作正常),但随后我尝试将数组值传递给另一个名为orderingSubmissionReceipt的方法,以便我最终可以在 order-summary 上呈现视图页。我正在使用会话,但它们似乎不起作用。谁能告诉我我缺少什么吗?
这是我的route.php
Route::get('/', function() { return redirect('home'); });
Route::get('home', 'HomeController@home');
Route::post('home', 'HomeController@activateCustomer');
Route::post('order-summary', 'HomeController@OrderingSubmission');
Route::get('order-summary', 'HomeController@orderingSubmissionReceipt');
Run Code Online (Sandbox Code Playgroud)
HomeController.php
public function orderingSubmission(Request $request)
{
$allValues2 = $request->get('users'); // This code works fine. It gets the array
Log::info('This is orderingSubmission.....: ' . print_r($allValues2, true));
Session::set('allValues2',$allValues2);
}
public function orderingSubmissionReceipt()
{
$allValues3 = Session::get('allValues2'); // This code is not getting the session value
Log::info('This is orderingSubmissionReceipt.....: ' . print_r($allValues3, true));
return view('order-summary', [ …Run Code Online (Sandbox Code Playgroud) 点击"btn1"按钮时,我显示了这个sideBar.因此,我没有按钮,而是想要一个具有相同标题的垂直条.基本上我想完成这个:
下面是我的代码到目前为止的样子.谁能指出我正确的方向?非常感谢提前.
<button (click)="openTab()">btn1</button>
<p-sidebar [modal]="false" class="menuPanel" [(visible)]="opened"
position="left" [showCloseIcon]="true" autoZIndex="true"
baseZIndex="99999">
This is the Title
</p-sidebar>
Run Code Online (Sandbox Code Playgroud) 我正在尝试打以下AWS终端节点:
https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users
Run Code Online (Sandbox Code Playgroud)
返回:
[{
"id": 1,
"name": "Mike"
},{
"id": 2,
"name": "Brian"
}]
Run Code Online (Sandbox Code Playgroud)
core.js:12501错误错误:未捕获(承诺):错误:请求失败,状态码为403错误:请求失败,状态码为403
这就是我获取密钥和令牌的方式(这一部分效果很好)
AWS.config.region = 'us-east-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-2:ehkjthf-sf23-12ds-xxxxxxxxx',
Logins: {
'cognito-idp.us-east-2.amazonaws.com/us-east-2_Raxxxx': this.id_token
}
});
console.log(AWS.config.credentials);
Run Code Online (Sandbox Code Playgroud)
现在,这就是我使用这些键和令牌进行GET调用的方式。
(AWS.config.credentials as AWS.Credentials).get(function(error: AWSError){
if(error){
console.log('Error ', error);
}else{
let request = {
host: 'https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users',
method: 'GET',
url: 'https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users',
path: '/users',
headers: {
"Content-Type":"application/json"
},
}
let signedRequest = aws4.sign(request,
{ …Run Code Online (Sandbox Code Playgroud)