-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurry-exercises.js
More file actions
49 lines (37 loc) · 1.07 KB
/
curry-exercises.js
File metadata and controls
49 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Setup
//==============
const _ = require("ramda")
const split = _.curry((delimiter, string) => string.split(delimiter))
// Exercise 1
//==============
const words = split(" ")
// Exercise 1a
//==============
//use map to make a new words fn that not only works on 1 string, but on an array of strings.
const sentences = _.map(words)
// Exercise 2
//==============
const filterQs = _.filter(_.test(/q/gi))
// Exercise 3
//==============
// Use the helper function _keepHighest to refactor max
const _keepHighest = (x, y) => (x >= y ? x : y) // <- leave be
// TODO: rewrite max in its "simplest" form
const max = _.reduce((acc, x) => _keepHighest(acc, x), 0)
// Bonus 1:
// ============
// wrap array's built in slice to be functional and curried like ramda fn's.
// //[1,2,3].slice(0, 2)
const slice = _.curry((init, final, xs) => xs.slice(init, final))
// Bonus 2:
// ============
// use slice to define a function take() that takes n elements from an array. make it curried
const take = _.curry(slice(0))
module.exports = {
words,
sentences,
filterQs,
max,
slice,
take,
}