Skip to content

Instantly share code, notes, and snippets.

@lubien
Forked from ronaiza-cardoso/negative-number-matrix.js
Last active March 21, 2017 00:09
Show Gist options
  • Save lubien/662c9e2e474b123f77420dde3a38a35b to your computer and use it in GitHub Desktop.
Save lubien/662c9e2e474b123f77420dde3a38a35b to your computer and use it in GitHub Desktop.
Count Negative Integers in Matrix
const
composeN = (...fs) => y =>
fs.reduceRight((x, f) => f(x), y)
, flatten = xs =>
xs.reduce((acc, x) => acc.concat(x))
, filter = pred => xs =>
xs.filter(pred)
, negative = x =>
x < 0
, prop = p => o =>
o[p]
, M =
[ [-1, 3, 4, 1]
, [ 2, 2, 4, 9]
, [ 4, 5, -7, 9]
]
composeN(
prop('length'),
filter(negative),
flatten
)(M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment