javascript Zadanie
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Zadanie相关的知识,希望对你有一定的参考价值。
Zdefiniować wyrażenie, które będzie zwracać sumę wartości kluczy `value`, których `state = true`.
```JavaScript
const a = [
{value: 5, state: true},
{value: 2, state: false},
{value: 3, state: true}
];
const b = ...
console.log(b) // 8 (5+3)
```
const a = [{value: 10, state: true}, {value: 2, state: false}, {value: 3, state: true}];
const sum = array => (array.reduce(
(total, object) => (total + (object.state && object.value)), 0));
console.log(sum(a)); // 13
const a = [
{ value: 5, state: true },
{ value: 2, state: false },
{ value: 3, state: true },
];
const getSum = arr =>
arr.reduce((prev, current) => (current.state ? prev + current.value : prev), 0);
console.log(getSum(a)); // 8
const b = a.filter((val) => val.state).map((val) => val.value || val.foo).reduce((a, b) => a + b, 0);
const a = [{value: 5, state: true}, {value: 2, state: false}, {value: 3, state: true}];
const b = a.filter(i => i.state).reduce((x,y) => x + y.value, 0);
console.log(b); // 8
以上是关于javascript Zadanie的主要内容,如果未能解决你的问题,请参考以下文章
BZOJ 3727 3727: PA2014 Final Zadanie (递推)
JavaScript介绍
javascript的题。
javascript JavaScript isset()等效: - JavaScript
JavaScript 使用JavaScript更改CSS(JavaScript)
JavaScript之基础-1 JavaScript(概述基础语法)