Temukan kotak sempurna berikutnya!

/*
// You might know some pretty large perfect squares. But what about the NEXT one?
// Complete the findNextSquare method that finds the next integral perfect square 
after the one passed as a parameter. Recall that an integral perfect square is an 
integer n such that sqrt(n) is also an integer.
*/

function findNextSquare(sq) {
  // Return the next square if sq is a perfect square, -1 otherwise
  let squareRoot = Math.sqrt(sq);
  const isDecimal = squareRoot - Math.floor(squareRoot) !== 0;
  
  return isDecimal ? -1 : (squareRoot + 1) ** 2
}

// With love @kouqhar
kouqhar