11
2- // This way it obeys DRT- Don't Repeat Youself
3- // And it is more readable and maintanable
2+ // This way it obeys DRT- Don't Repeat Youself
3+ // And it is more readable and maintanable
44
5- const radius = [ 3 , 1 , 2 , 4 ] ;
5+ const radius = [ 3 , 1 , 2 , 4 ] ;
66
7- const area = function ( radius ) {
8- return Math . PI * radius * radius ;
9- }
7+ const area = function ( radius ) {
8+ return Math . PI * radius * radius ;
9+ }
1010
11- const circumference = function ( radius ) {
12- return 2 * Math . PI * radius ;
13- }
11+ const circumference = function ( radius ) {
12+ return 2 * Math . PI * radius ;
13+ }
1414
15- const diameter = function ( radius ) {
16- return 2 * radius ;
17- }
15+ const diameter = function ( radius ) {
16+ return 2 * radius ;
17+ }
1818
19- const calculate = function ( radius , logic ) {
20- const output = [ ] ;
21- for ( let i = 0 ; i < radius . length ; i ++ ) {
22- output . push ( logic ( radius [ i ] ) ) ;
19+ const calculate = function ( radius , logic ) {
20+ const output = [ ] ;
21+ for ( let i = 0 ; i < radius . length ; i ++ ) {
22+ output . push ( logic ( radius [ i ] ) ) ;
23+ }
24+ return output ;
2325 }
24- return output ;
25- }
2626
27- console . log ( calculate ( radius , area ) ) ;
28- console . log ( calculate ( radius , circumference ) ) ;
29- console . log ( calculate ( radius , diameter ) ) ;
27+ console . log ( calculate ( radius , area ) ) ;
28+ console . log ( calculate ( radius , circumference ) ) ;
29+ console . log ( calculate ( radius , diameter ) ) ;
0 commit comments