Last active
December 31, 2015 23:29
-
-
Save ThomasMeier/8060479 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 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