From d9bec96f967b7087be8bd0d7f4497f33420f1e85 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Wed, 22 Jul 2015 23:40:39 +0500 Subject: [PATCH] lodash: added _.round() method --- lodash/lodash-tests.ts | 14 ++++++++++++++ lodash/lodash.d.ts | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 627dda565c..a7cec7abb1 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -534,6 +534,20 @@ result = <_.LoDashWrapper>_([4, 2, 8, 6]).min(); result = <_.LoDashWrapper>_(stoogesAges).min(function (stooge) { return stooge.age; }); result = <_.LoDashWrapper>_(stoogesAges).min('age'); +// _.round +result = _.round(4.006); +// → 4 +result = _.round(4.006, 2); +// → 4.01 +result = _.round(4060, -2); +// → 4100 +result = _(4.006).round(); +// → 4 +result = _(4.006).round(2); +// → 4.01 +result = _(4060).round(-2); +// → 4100 + result = _.sum([4, 2, 8, 6]); result = _.sum([4, 2, 8, 6], function(v) { return v; }); result = _.sum({a: 2, b: 4}); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 7bc1df648d..860239dcd0 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3794,6 +3794,24 @@ declare module _ { whereValue: W): LoDashWrapper; } + //_.round + interface LoDashStatic { + /** + * Calculates n rounded to precision. + * @param n The number to round. + * @param precision The precision to round to. + * @return Returns the rounded number. + */ + round(n: number, precision?: number): number; + } + + interface LoDashWrapper { + /** + * @see _.round + */ + round(precision?: number): number; + } + //_.sum interface LoDashStatic { /**