Here's a brain teaser for you:
/**
* Let's figure out the optimal number of rows and columns for your garden to be as square as possible, based on the number of seeds you have.
*
* @param {number} seedCount - The total number of seeds in your packet.
* @return {array} - An array representing the required rows and columns for your grid layout (e.g. [4, 5] equals a 4-row by 5-column grid)
*/
function grid(seedCount) {
// Your code goes here
}
This isn't a programming assignment, just a fun challenge from one of those coding platforms that has left me scratching my head. I might be overcomplicating things, so any insights would be greatly appreciated...
UPDATE: Initial attempt (No luck)
function grid(seedCount) {
/* Insert your ingenious solution here! */
var num1 = Math.sqrt(seedCount)
num1 = Math.round(num1)
while(seedCount % num1 != 0){
num1++
}
num2 = seedCount / num1
var Arr = [num1,num2]
return Arr
}