Created
August 12, 2020 01:05
-
-
Save cplpearce/b582a2160d79d6d7b4be7e7b38fa8f72 to your computer and use it in GitHub Desktop.
Kata 15 - Square Code
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
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