|
|
|
|
|
by spion
4013 days ago
|
|
Here are some fun counter-examples let sqr = x => Math.pow(x, 2)
let property = name => obj => obj[name]
let distance = p1 => p2 => Math.sqrt(sqr(p2.x - p1.x) + sqr(p2.y - p1.y))
let byComparing = f => (x, y) => {
let fx = f(x), fy = f(y)
fx < fy ? -1 : fx > fy ? 1 : 0
}
let points = [{x: 1, y: 2}, ...]
let byX = points.slice().sort(byComparing(property('x'))
let byStartDistance = points.slice().sort(byComparing(distance({x: 0, y: 0}))
|
|
That said, the arrow function is a massive win in both examples. I've been using it for a while and never had any issue mistaking it with <= or >=. The linter would probably catch it anyway.