小编use*_*287的帖子

如何使用localecompare对包含负值的数字数组进行排序?

我正在尝试从最低值到最高值对数组进行排序。

下面的示例显示它已经以这种方式排序

var array = ["-394","-275","-156","-37","82","201","320","439","558","677","796"];
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时:

var array = ["-394","-275","-156","-37","82","201","320","439","558","677","796"];
Run Code Online (Sandbox Code Playgroud)

这返回(我不确定发生了什么排序):

["-37", "-156", "-275", "-394", "82", "201", "320", "439", "558", "677", "796"]
Run Code Online (Sandbox Code Playgroud)

我看了看:

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

但似乎并未提及任何专门处理负数的内容。

对包含负值的数字数组进行排序的正确方法是什么?

javascript arrays

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

C#是否等同于python的type()函数?

我正在学习C#并且有一个非常基本的背景Python,我熟悉了type()函数,其中变量的数据类型可以通过以下方式返回:

type(myVariable)

有没有C#相当于这个功能?

我在上下文中要求在使用var例如:创建的C#变量上使用这样的函数:

var myNewVariable = "Hello!"

我一般使用显式数据类型,例如:

string myNewString = "Hello!"

但我只是想知道使用var默认值创建的变量是什么数据类型并且认为类似的东西type()将是检查" 引擎盖下 " 发生了什么的好方法.

c# python types

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

如何将wsgi.url_scheme设置为瓶中的https?

我想将所有请求重定向httphttps.

是否有一个通用的方法来设置wsgi.url_scheme,以https在Python 2.7瓶的应用程序?

该应用程序的一般结构是:

setup.py  // contains 'install_requires'  
wsgi  
 - myapplication.py  // the custom application containing bottle routes
Run Code Online (Sandbox Code Playgroud)

wsgi.url_scheme 似乎与环境变量有关:

http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme

但我不确定如何实际"设置"环境变量https以及是否可以在setup.pymyapplication.py文件中完成.

这里有一段代码:

https://github.com/defnull/bottle/issues/347

def i_am_https_dammit(app):
    def https_app(environ, start_response):
        environ['wsgi.url_scheme'] = 'https'
        return app(environ, start_response)
    return https_app
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何实现这个要点,因为我对应用程序的调用是来自软木塞而且只是使用:

application=default_app()  
session_opts = {
    'session.cookie_expires': True,
    'session.encrypt_key': 'please use a random key and keep it secret!',
    'session.httponly': True,
    'session.timeout': 3600 * 24,  # 1 day
    'session.type': …
Run Code Online (Sandbox Code Playgroud)

https wsgi bottle python-2.7 openshift

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

按iso字符串降序排序不起作用

期望的行为

按对象的iso_string属性对对象数组进行排序,降序.

实际行为

数组顺序不会更改.

我试过的

我必须在某个地方犯了一个简单的错误,因为多个帖子确认这是正确的sort()语法.

iso_string值生成new Date().toISOString();

var dates = [{
  "formatted_date": "22/09/2018 @ 04:02pm",
  "iso_string": "2018-09-22T06:02:22.485Z"
}, {
  "formatted_date": "22/09/2018 @ 04:12pm",
  "iso_string": "2018-09-22T06:12:04.471Z"
}, {
  "formatted_date": "22/09/2018 @ 04:05pm",
  "iso_string": "2018-09-22T06:05:45.818Z"
}, {
  "formatted_date": "22/09/2018 @ 04:00pm",
  "iso_string": "2018-09-22T06:00:46.954Z"
}, {
  "formatted_date": "22/09/2018 @ 03:56pm",
  "iso_string": "2018-09-22T05:56:13.968Z"
}];

var sorted_dates = dates.sort(function(a, b) {
  return b.iso_string - a.iso_string;
});

console.log(sorted_dates);
Run Code Online (Sandbox Code Playgroud)

编辑: 我包装了值new Date()并正确排序.

javascript isodate

0
推荐指数
2
解决办法
162
查看次数

标签 统计

javascript ×2

arrays ×1

bottle ×1

c# ×1

https ×1

isodate ×1

openshift ×1

python ×1

python-2.7 ×1

types ×1

wsgi ×1