Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Find the next perfect square!

/*
// 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: Disabling right click using Javascript 
Javascript :: vue reset all data to default 
Javascript :: classlist 
Javascript :: unshift method in javascript 
Javascript :: nested for loop js 
Javascript :: how to find smallest number in array js 
Javascript :: count object in array javascript 
Javascript :: how to get the current time of a audio in js 
Javascript :: mongoose connect 
Javascript :: delete row in html table using javascript 
Javascript :: if browsertab is active jquery 
Javascript :: iterate through object javascript 
Javascript :: javascript find the second highest Element from array 
Javascript :: elasticsearch bulk json 
Javascript :: javascript append html 
Javascript :: golang json omitempty struct 
Javascript :: make button inside datatable 
Javascript :: javascript fetch request GET 
Javascript :: form data 
Javascript :: how to export a function in nodejs 
Javascript :: react arrow funvtion 
Javascript :: ajax data not reflecting after refresh particular div jquery 
Javascript :: json_decode javascript 
Javascript :: js get all arguments from function 
Javascript :: toggle boolean state react 
Javascript :: string splice javascript 
Javascript :: How to create sequelize connection in javascript 
Javascript :: webpack babel loaders/plugin installation 
Javascript :: javascript event listener 
Javascript :: jsx loop array 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =