S13_A3_T3.js (854B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: | 6 The Identifier in a FunctionExpression can be referenced from inside the 7 FunctionExpression's FunctionBody to allow the function calling itself 8 recursively 9 es5id: 13_A3_T3 10 description: Creating simple recursive function that calculates factorial 11 ---*/ 12 13 function __func(arg){ 14 if (arg === 1) { 15 return arg; 16 } else { 17 return __func(arg-1)*arg; 18 } 19 }; 20 21 var fact_of_3 = __func(3); 22 23 ////////////////////////////////////////////////////////////////////////////// 24 //CHECK#1 25 if (fact_of_3 !== 6) { 26 throw new Test262Error("#1: fact_of_3 === 6. Actual: fact_of_3 ==="+fact_of_3); 27 } 28 // 29 ////////////////////////////////////////////////////////////////////////////// 30 31 reportCompare(0, 0);