数组中的角令减速器

时间:2019-06-04 02:35:47

标签: angular rxjs

我了解到,要使用 rxjs 在Angular中对数组进行计数,例如,如果要计数:[{id: 1, items: [10, 20, 30]}]我将使用以下代码:

const item = from([{id: 1, items: [10, 20, 30]}]);
item.pipe(
  map(actions => actions.items),
  mergeAll(),
  reduce((acc, i) => acc + i, 0)
).subscribe(p => console.log('Print 60: ', p)); 

问题是如何在以下阵列中制造减速器:

const items = [
{
  id: 1,
  boxing: [1, 2, 2]
},
{
  id: 2,
  boxing: [10, 10, 20]
}]; 

预期结果:

[{
  id: 1,
  boxing: 5
},
{
  id: 2,
  boxing: 40
}]

感谢您的帮助

2 个答案:

答案 0 :(得分:6)

您可以使用 DOMAIN_NAME=InfraDomain12213 ADMIN_LISTEN_PORT=7001 ADMIN_NAME=weblogic ADMIN_HOST=InfraAdminContainer ADMINISTRATION_PORT_ENABLED=true ADMINISTRATION_PORT=9002 MANAGEDSERVER_PORT=8001 MANAGED_NAME=infraServer1 RCUPREFIX=INFRA6 PRODUCTION_MODE=dev CONNECTION_STRING=MyDB:1521/ORCLPDB1.localdomain DOMAIN_HOST_VOLUME=C:\Users\xxx reduce作为

map

答案 1 :(得分:0)

一种方法可以是这样。

AIDEVERSUSCATCH:api-console evan.dhillon$ docker-compose up
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Starting api-console_app_1   ... done
Starting api-console_redis_1 ... done
Attaching to api-console_app_1, api-console_redis_1
redis_1  | 1:C 04 Jun 2019 03:12:27.660 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 04 Jun 2019 03:12:27.660 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 04 Jun 2019 03:12:27.660 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 04 Jun 2019 03:12:27.661 * Running mode=standalone, port=6379.
redis_1  | 1:M 04 Jun 2019 03:12:27.661 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 04 Jun 2019 03:12:27.661 # Server initialized
redis_1  | 1:M 04 Jun 2019 03:12:27.661 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1  | 1:M 04 Jun 2019 03:12:27.661 * DB loaded from disk: 0.000 seconds
redis_1  | 1:M 04 Jun 2019 03:12:27.661 * Ready to accept connections
app_1    | Express server listening on port 3000
app_1    | Error Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
app_1    | Error AbortError: Redis connection lost and command aborted. It might have been processed.
app_1    | events.js:183
app_1    |       throw er; // Unhandled 'error' event
app_1    |       ^
app_1    | 
app_1    | Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
app_1    |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
api-console_app_1 exited with code 1