forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.js
36 lines (29 loc) · 1010 Bytes
/
update.js
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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('update', function() {
it('updates the value at the given index of the supplied array', function() {
eq(R.update(2, 4, [0, 1, 2, 3]), [0, 1, 4, 3]);
});
it('offsets negative indexes from the end of the array', function() {
eq(R.update(-3, 4, [0, 1, 2, 3]), [0, 4, 2, 3]);
});
it('returns the original array if the supplied index is out of bounds', function() {
var list = [0, 1, 2, 3];
eq(R.update(4, 4, list), list);
eq(R.update(-5, 4, list), list);
});
it('does not mutate the original array', function() {
var list = [0, 1, 2, 3];
eq(R.update(2, 4, list), [0, 1, 4, 3]);
eq(list, [0, 1, 2, 3]);
});
it('curries the arguments', function() {
eq(R.update(2)(4)([0, 1, 2, 3]), [0, 1, 4, 3]);
});
it('accepts an array-like object', function() {
function args() {
return arguments;
}
eq(R.update(2, 4, args(0, 1, 2, 3)), [0, 1, 4, 3]);
});
});