Created
June 14, 2016 09:57
-
-
Save DonaldKellett/3c49167ae6ec9e27e90563216266c433 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.21) | |
// Compass (v1.0.3) | |
// ---- | |
/* | |
Recursion in Sass #1 - Factorial | |
(c) Donald Leung. All rights reserved. | |
*/ | |
// Code | |
@function factorial($n) { | |
@return if($n == 0, 1, $n * factorial($n - 1)); | |
} | |
// Pseudo-test cases | |
.test-1 { | |
n: 3; | |
expected: 6; | |
actual: factorial(3); | |
pass: factorial(3) == 6; | |
} | |
.test-2 { | |
n: 5; | |
expected: 120; | |
actual: factorial(5); | |
pass: factorial(5) == 120; | |
} | |
.test-3 { | |
n: 6; | |
expected: 720; | |
actual: factorial(6); | |
pass: factorial(6) == 720; | |
} | |
.test-4 { | |
n: 10; | |
expected: 3628800; | |
actual: factorial(10); | |
pass: factorial(10) == 3628800; | |
} | |
.test-5 { | |
n: 0; | |
expected: 1; | |
actual: factorial(0); | |
pass: factorial(0) == 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Recursion in Sass #1 - Factorial | |
(c) Donald Leung. All rights reserved. | |
*/ | |
.test-1 { | |
n: 3; | |
expected: 6; | |
actual: 6; | |
pass: true; | |
} | |
.test-2 { | |
n: 5; | |
expected: 120; | |
actual: 120; | |
pass: true; | |
} | |
.test-3 { | |
n: 6; | |
expected: 720; | |
actual: 720; | |
pass: true; | |
} | |
.test-4 { | |
n: 10; | |
expected: 3628800; | |
actual: 3628800; | |
pass: true; | |
} | |
.test-5 { | |
n: 0; | |
expected: 1; | |
actual: 1; | |
pass: true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment