File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 268268* ** Sorts**
269269 * [ AlphaNumericalSort] ( Sorts/AlphaNumericalSort.js )
270270 * [ BeadSort] ( Sorts/BeadSort.js )
271+ * [ BinaryInsertionSort] ( Sorts/BinaryInsertionSort.js )
271272 * [ BogoSort] ( Sorts/BogoSort.js )
272273 * [ BubbleSort] ( Sorts/BubbleSort.js )
273274 * [ BucketSort] ( Sorts/BucketSort.js )
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ const PHI = (1 + SQ5) / 2 // definition of PHI
55// theoretically it should take O(1) constant amount of time as long
66// arithmetic calculations are considered to be in constant amount of time
77export const EvenFibonacci = ( limit ) => {
8+ if ( limit < 1 ) throw new Error ( 'Fibonacci sequence limit can\'t be less than 1' )
9+
810 const highestIndex = Math . floor ( Math . log ( limit * SQ5 ) / Math . log ( PHI ) )
911 const n = Math . floor ( highestIndex / 3 )
10- return ( ( PHI ** ( 3 * n + 3 ) - 1 ) / ( PHI ** 3 - 1 ) -
11- ( ( 1 - PHI ) ** ( 3 * n + 3 ) - 1 ) / ( ( 1 - PHI ) ** 3 - 1 ) ) / SQ5
12+ return Math . floor ( ( ( PHI ** ( 3 * n + 3 ) - 1 ) / ( PHI ** 3 - 1 ) -
13+ ( ( 1 - PHI ) ** ( 3 * n + 3 ) - 1 ) / ( ( 1 - PHI ) ** 3 - 1 ) ) / SQ5 )
1214}
Original file line number Diff line number Diff line change 1+ import { EvenFibonacci } from '../Problem002'
2+
3+ describe ( 'Even Fibonacci numbers' , ( ) => {
4+ it ( 'should throw error when limit is less than 1' , ( ) => {
5+ expect ( ( ) => EvenFibonacci ( - 1 ) ) . toThrowError ( 'Fibonacci sequence limit can\'t be less than 1' )
6+ } )
7+ test ( 'when limit is greater than 0' , ( ) => {
8+ expect ( EvenFibonacci ( 40 ) ) . toBe ( 44 )
9+ } )
10+ // Project Euler Condition Check
11+ test ( 'when limit is 4 million' , ( ) => {
12+ expect ( EvenFibonacci ( 4e6 ) ) . toBe ( 4613732 )
13+ } )
14+ } )
You can’t perform that action at this time.
0 commit comments