-
Code const factorial = n => { f=1; while(n--) f*=n+1; return f }
Test Cases const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold=0; describe("factorial", function() { it("should test", function() { assert.strictEqual(factorial( 0 ), 1); assert.strictEqual(factorial( 1 ), 1); assert.strictEqual(factorial( 2 ), 2); assert.strictEqual(factorial( 3 ), 6); assert.strictEqual(factorial( 4 ), 24); assert.strictEqual(factorial( 5 ), 120); assert.strictEqual(factorial( 6 ), 720); assert.strictEqual(factorial( 7 ), 5040); assert.strictEqual(factorial( 8 ), 40320); assert.strictEqual(factorial( 9 ), 362880); assert.strictEqual(factorial( 10 ), 3628800); }); });
Output:
-
Code factorial=n=>(x=1,[...{*[Symbol.iterator](){for(i=2;i<=n;i++)yield x*=i}}],x)- const factorial = n => { f=1; while(n--) f*=n+1; return f }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}