Created
August 5, 2014 08:50
-
-
Save P1xt/e932a55853fa6b6002ee to your computer and use it in GitHub Desktop.
Reverse Groups
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
var fs = require("fs"); | |
fs.readFileSync(process.argv[2]).toString().split('\n').forEach(function (line) { | |
if (line != "") { | |
var parsedLine = line.split(";"); | |
var k = parsedLine[1]; | |
var digits = parsedLine[0].split(","); | |
var length = digits.length; | |
if (k > 1) { | |
for (var i = 1; i <= length; i++) { | |
if (i % (k) === 0) { | |
var upper = i - 1; | |
var lower = i - k; | |
var tmp; | |
while (upper > lower) { | |
tmp=digits[upper]; | |
digits[upper]=digits[lower]; | |
digits[lower]=tmp; | |
upper--; | |
lower++; | |
} | |
} | |
} | |
} | |
console.log(digits.join()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment