Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 12, 2020 01:05
Show Gist options
  • Save cplpearce/b582a2160d79d6d7b4be7e7b38fa8f72 to your computer and use it in GitHub Desktop.
Save cplpearce/b582a2160d79d6d7b4be7e7b38fa8f72 to your computer and use it in GitHub Desktop.
Kata 15 - Square Code
const squareCode = function(message) {
msg = message.replace(/ +/g, '');
let len = msg.length;
let sqR = Math.ceil(Math.sqrt(len));
let rS = [];
for (let r = 0; r < sqR; r++) {
for (let i = 0; i < sqR; i++) {
rS.push(msg[r + (i * sqR)])
}
rS.push(' ');
}
return rS.join('');
};
console.log(squareCode("chill out"));
console.log(squareCode("feed the dog"));
console.log(squareCode("have a nice day"));
console.log(squareCode("if man was meant to stay on the ground god would have given us roots"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment