-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 888 Bytes
/
index.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
37
38
39
40
41
42
module.exports = function(yesterday, today, options) {
var changes = [];
options = options || {};
var offset = options.ordinal ? 1 : 0;
yesterday.forEach(function(element, idx) {
var todayIndex = today.indexOf(element);
// Dropped out of the rankings
if (todayIndex === -1) {
changes.push({
element: element,
was: idx + offset,
now: null
});
// Moved rankings
} else if (todayIndex !== idx) {
changes.push({
element: element,
was: idx + offset,
now: todayIndex + offset
});
}
});
// Newly added to the rankings
today.forEach(function(element, idx) {
var yesterdayIndex = yesterday.indexOf(element);
if (yesterdayIndex === -1) {
changes.push({
element: element,
was: null,
now: idx + offset
});
}
});
return changes;
};