Aar*_*ron 5 javascript functional-programming
I'm new to functional programming and I just ran into something and was wondering if there was a way around this.
Suppose I have
myArray = [
{ a : 1 }
{ a : 4 }
{ a : 5 }
{ a : 6 }
{ a : 7 }
{ a : 8 }
]
Run Code Online (Sandbox Code Playgroud)
Let say I need to do statistical operations on this data set such as
const median = myArray[ Math.ceil( myArray.length / 2 ) ]['a'] // Math.ceil .. Side Effect?
const fiveOrMore = myArray.filter( value => value.a >= 5 )
const lessThanFive = myArray.filter( value => value.a < 5 )
Run Code Online (Sandbox Code Playgroud)
Some arbitrary examples. The problem with this as of right now is that with increasing amount of statistical operations I need to do, the efficiency decreases.
With imperative style, I could do everything in ONE for loop. Is this the wrong approach to functional programming that I am taking or is it a trade off of functional programming paradigm itself?
| 归档时间: |
|
| 查看次数: |
1041 次 |
| 最近记录: |