You are viewing a single comment's thread. Return to all comments →
JS Solution :
function encryption(s) { // Write your code here const spacesRemovedString = s.split(' ').join('') const squareRoot = Math.sqrt(spacesRemovedString.length) const columns = Math.ceil(squareRoot) const splitString = spacesRemovedString.split('') const stringMatrix = [] const encrytedStringArray = [] while (splitString.length > 0) { stringMatrix.push(splitString.splice(0, columns)) } for (let i = 0; i < columns; i++) { encrytedStringArray.push(stringMatrix.reduce((acc, currentValue) => { return acc + (currentValue[i] ?? '') }, '')) } return encrytedStringArray.join(' ') }
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
JS Solution :