Last active
February 20, 2018 11:20
-
-
Save eduzol/3f5a3800d1bffd50b2fadb97b46c8734 to your computer and use it in GitHub Desktop.
Javascript method populationGrowth(simulationLength) that determines how many amoebas will exist after simulationLength steps
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
let fibonacci = ( n , dict ) =>{ | |
if ( dict[n] ){ | |
return dict[n]; | |
} | |
if ( n <= 1 ){ | |
return 1; | |
} | |
let fibN = fibonacci(n-1 , dict) + fibonacci(n-2 , dict); | |
return fibN; | |
} | |
let populationGrowth = ( simulationLength ) => { | |
if ( simulationLength < 0 ){ | |
return -1; | |
} | |
let dict = {}; | |
length = fibonacci(simulationLength , dict ); | |
return length; | |
}; | |
for ( n = 0 ; n < 10 ; n++ ){ | |
console.log(populationGrowth(n)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment