Skip to content

eles.reduce(fn, initial)

eles.reduce — Collection > Iteration and aggregation. Cytoscape.js signatures, parameters and return contract.

eles.reduce — Collection › Iteration and aggregation

Preview · Collection › Iteration and aggregation

Read in the complete API reference · All API members

// Fold the collection into a single value
eles.reduce<T>(fn: ( acc: T, ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T, initial: T): T

Fold the collection into a single value.

Parameters
NameDescription
fn: ( acc: T, ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T

( accumulator, ele, i, eles)

initial: T

the starting accumulator (required, unlike Array#reduce)

Returns T

the final accumulator

Example

const count = eles.reduce((sum, ele) => sum + (ele.isNode() ? 1 : 0), 0);
console.log(count); // 3

Example graph and handle setup