Created
October 21, 2016 23:36
-
-
Save TaylorAckley/a796a26f06cb226a71363aadc36357a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrCollection() { | |
this.createArray = function(len) { | |
var ret = []; | |
for(var i = 0; i < len; i++) { | |
ret.push(i); | |
} | |
return ret; | |
}; | |
this.reduceToPrime = function(arr) { | |
var ret = arr.filter(function(value) { | |
var isPrime = function(value) { | |
var divisor = 2; | |
while (value > divisor) { | |
if (value % divisor === 0) { | |
return false; | |
} | |
divisor++; | |
} | |
return true; | |
}; | |
console.log(isPrime(value), value); | |
return isPrime(value) === true; | |
}); | |
return ret; | |
}; | |
} | |
Array.prototype.remove = function(index) { | |
var ind = this.indexOf(index); | |
this.splice(index, 1); | |
}; | |
var myArray = new arrCollection(); | |
var bigArr = myArray.createArray(100); | |
bigArr.remove(0); | |
console.log(bigArr); | |
var smallerArr = myArray.reduceToPrime(bigArr); | |
console.log(smallerArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment