Skip to content

Commit

Permalink
refactor(ArrayMap): update ArrayMap to es2015 class (#3613)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy authored and TheLarkInn committed Dec 29, 2016
1 parent 4015882 commit 79791a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
83 changes: 45 additions & 38 deletions lib/ArrayMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,56 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function ArrayMap() {
this.keys = [];
this.values = [];
}
module.exports = ArrayMap;

ArrayMap.prototype.get = function(key) {
for(var i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
return this.values[i];
"use strict";

class ArrayMap {
constructor() {
this.keys = [];
this.values = [];
}

get(key) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
return this.values[i];
}
}
return;
}
return;
};

ArrayMap.prototype.set = function(key, value) {
for(var i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.values[i] = value;
return this;

set(key, value) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.values[i] = value;
return this;
}
}
this.keys.push(key);
this.values.push(value);
return this;
}
this.keys.push(key);
this.values.push(value);
return this;
};

ArrayMap.prototype.remove = function(key) {
for(var i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.keys.splice(i, 1);
this.values.splice(i, 1);
return true;

remove(key) {
for(let i = 0; i < this.keys.length; i++) {
if(this.keys[i] === key) {
this.keys.splice(i, 1);
this.values.splice(i, 1);
return true;
}
}
return false;
}
return false;
};

ArrayMap.prototype.clone = function() {
var newMap = new ArrayMap();
for(var i = 0; i < this.keys.length; i++) {
newMap.keys.push(this.keys[i]);
newMap.values.push(this.values[i]);

clone() {
const newMap = new ArrayMap();

for(let i = 0; i < this.keys.length; i++) {
newMap.keys.push(this.keys[i]);
newMap.values.push(this.values[i]);
}
return newMap;
}
return newMap;
};
}

module.exports = ArrayMap;
1 change: 0 additions & 1 deletion test/fixtures/temp-1000/file.js

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/temp-1000/file2.js

This file was deleted.

0 comments on commit 79791a5

Please sign in to comment.