const R = require("ramda")
const groupByWithIdx = R.addIndex(R.groupBy);
const main = R.pipe(
String,
R.split(''),
R.reverse,
groupByWithIdx((s, i) => Math.floor(i / 3)),
R.values,
R.reverse,
R.map(R.reverse),
R.map(R.join('')),
R.join(','))
main(1234567)