Skip to content

Instantly share code, notes, and snippets.

@TaylorAckley
Created October 21, 2016 23:36
Show Gist options
  • Save TaylorAckley/a796a26f06cb226a71363aadc36357a9 to your computer and use it in GitHub Desktop.
Save TaylorAckley/a796a26f06cb226a71363aadc36357a9 to your computer and use it in GitHub Desktop.
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