OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-rest-parameters --harmony-arrow-functions | 5 // Flags: --harmony-rest-parameters |
6 // Flags: --min-preparse-length=0 | 6 // Flags: --min-preparse-length=0 |
7 | 7 |
8 function variadic(co, ...values) { | 8 function variadic(co, ...values) { |
9 var sum = 0; | 9 var sum = 0; |
10 while (values.length) { | 10 while (values.length) { |
11 sum += co * values.pop(); | 11 sum += co * values.pop(); |
12 } | 12 } |
13 return sum; | 13 return sum; |
14 } | 14 } |
15 | 15 |
16 var arrowVariadic = (co, ...values) => { | 16 var arrowVariadic = (co, ...values) => { |
17 var sum = 0; | 17 var sum = 0; |
18 while (values.length) { | 18 while (values.length) { |
19 sum += co * values.pop(); | 19 sum += co * values.pop(); |
20 } | 20 } |
21 return sum; | 21 return sum; |
22 } | 22 } |
23 | 23 |
24 assertEquals(1, variadic.length); | 24 assertEquals(1, variadic.length); |
25 assertEquals(1, arrowVariadic.length); | 25 assertEquals(1, arrowVariadic.length); |
26 | 26 |
27 assertEquals(90, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); | 27 assertEquals(90, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); |
28 assertEquals(74, variadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); | 28 assertEquals(74, variadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); |
29 assertEquals(110, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); | 29 assertEquals(110, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); |
30 | 30 |
31 assertEquals(90, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); | 31 assertEquals(90, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); |
32 assertEquals(74, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); | 32 assertEquals(74, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); |
33 assertEquals(110, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); | 33 assertEquals(110, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); |
OLD | NEW |