Project

General

Profile

Actions

Feature #14399

open

Add Enumerable#product

Added by jzakiya (Jabari Zakiya) almost 7 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:85085]

Description

For similar reasons for creating Enumerable#sum a companion method
Enumerable#product is also very useful. Taking the product of
numbers in arrays is a common operation in many numerical algorithms,
especially in number theory and cryptography, and its optimization in
Ruby will make it more conducive to math heavy algorithms and tasks.

This

> [2,3,5,7].reduce(:*) => 210

can be optimized to this

> [2,3,5,7].product => 210

It should also allow an initial value

> [2,3,5,7].product(2) => 420

> [2,3,5,7].product(0.5) => 105

Crystal already has this method.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0