UNPKG

867 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.rpoplpush = rpoplpush;
7function rpoplpush(source, destination) {
8 if (this.data.has(source) && !(this.data.get(source) instanceof Array)) {
9 throw new Error("Key " + source + " does not contain a list");
10 }
11 if (this.data.has(destination) && !(this.data.get(destination) instanceof Array)) {
12 throw new Error("Key " + destination + " does not contain a list");
13 }
14
15 if (!this.data.has(source) || this.data.get(source).length === 0) {
16 return null;
17 }
18
19 if (!this.data.has(destination)) {
20 this.data.set(destination, []);
21 }
22
23 var newSource = this.data.get(source);
24 var item = newSource.pop();
25
26 var newDest = this.data.get(destination);
27 newDest.unshift(item);
28
29 this.data.set(source, newSource);
30 this.data.set(destination, newDest);
31
32 return item;
33}
\No newline at end of file