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