home > 比較編 > Perl, PHP, Python, Ruby > arrays >

ForNext

Only Do What Only You Can Do

122. reduce

VBScript

JScript

Perl

use List::Util 'reduce';

reduce { $x + $y } 0, (1,2,3)

PHP

array_reduce(array(1,2,3),
  function($x,$y) {
    return $x+$y;
  }, 0)

Python

# import needed in Python 3 only
from functools import reduce

reduce(lambda x, y: x+y, [1,2,3], 0)

Ruby

[1,2,3].inject(0) { |m,o| m+o }



PowerShell

Scala

F#

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system