Skip to content

Instantly share code, notes, and snippets.

@ThomasMeier
Last active December 31, 2015 23:29
Show Gist options
  • Save ThomasMeier/8060479 to your computer and use it in GitHub Desktop.
Save ThomasMeier/8060479 to your computer and use it in GitHub Desktop.
function generators ( group, operation, groupMod) {
var generatorList = [];
for ( var element in group ) {
var elementCycle = [];
for (var i = 1; i <= groupMod; i++) {
if (operation == 'mult') {
elementCycle.push(Math.pow(element, i));
} else {
elementCycle.push((element * i));
}
for (var i = 0; i < elementCycle.length; i++) {
elementCycle[i] = elementCycle[i] % groupMod;
}
elementCycle.sort();
var validComparison = true;
for (var i = 0; i < group.length; i++) {
if ( group[i] !== elementCycle[i] ) {
validComparison = false;
}
}
if (validComparison)
generatorList.push(element);
}
}
return generatorList;
}
// generators([1,3,5,7,9,13,15,17,19,21], 'mult', 22);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment