Skip to content

Commit

Permalink
[UPDATE] clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Mar 16, 2015
1 parent 6838047 commit 7ec054a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
Expand Down
53 changes: 34 additions & 19 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ function registerMethod(obj, name, fun){
}

registerMethod(Array.prototype, "compare",function(testArr){
if (this.length != testArr.length) return false;
if ( this.length !== testArr.length ) {
return false;
}
for (var i = 0; i < testArr.length; i++) {
if (this[i].compare) {
if (!this[i].compare(testArr[i])) return false;
if ( this[i].compare ) {
if ( !this[i].compare( testArr[i] ) ) {
return false;
}
}
if ( this[i] !== testArr[i] ) {
return false;
}
if (this[i] !== testArr[i]) return false;
}
return true;
});
Expand Down Expand Up @@ -98,7 +104,7 @@ registerMethod(Array.prototype, "cummax", function(){

registerMethod(Array.prototype, "clean", function(deleteValue) {
for (var i = 0; i < this.length; i++) {
if (this[i] == deleteValue) {
if (this[i] === deleteValue) {
this.splice(i, 1);
i--;
}
Expand All @@ -108,7 +114,7 @@ registerMethod(Array.prototype, "clean", function(deleteValue) {

registerMethod(Array.prototype, "contains", function(elem){
for (var q = 0; q < this.length; q++){
if (elem == this[q]){
if (elem === this[q]){
return true;
}
}
Expand All @@ -121,38 +127,47 @@ registerMethod(Array.prototype, "pickRandom", function(){
});

registerMethod(Array.prototype, "pickRandomElements",function(no){
if (no > this.length) no = this.length;
if ( no > this.length ) {
no = this.length;
}
var list = [];
while(list.length < no){
while( list.length < no ) {
var t = parseInt(Math.random() * this.length);
if (list.contains(t) === false) list.push(t);
if ( list.contains(t) === false ) {
list.push(t);
}
}
var target = [];
for (var i = 0; i < list.length; i++){
target.push (this[ list[i]] );
for (var i = 0; i < list.length; i++) {
target.push ( this[ list[i] ] );
}
return target;
});
});

registerMethod(Array.prototype, "containsAll", function(list){
registerMethod(Array.prototype, "containsAll", function(list){
for (var i = 0; i < list.length; i++){
if (this.contains(list[i]) === false) return false;
if ( this.contains(list[i]) === false ) {
return false;
}
}
return true;
});
});

registerMethod(Array.prototype, "containsAny", function(list){
for (var i = 0; i < list.length; i++){
if (this.contains(list[i]) === true) return true;
if ( this.contains(list[i]) === true ) {
return true;
}
}
return false;
});

registerMethod(Array.prototype, "removeItemAt", function(index){
var list = [];
for (var q = 0; q < this.length; q++){
if (q != index)
list.push(this[q]);
if ( q !== index ) {
list.push(this[q]);
}
}
this.length = 0;
for (var l = 0; l < list.length; l++){
Expand Down Expand Up @@ -182,7 +197,7 @@ registerMethod(Array.prototype, "unique", function(){
var res = [];
for(var i = 0; i < this.length; i++){
var elem = this[i];
if (res.contains(elem) === false){
if ( res.contains(elem) === false ){
res.push(elem);
}
}
Expand Down

0 comments on commit 7ec054a

Please sign in to comment.