Advertisement
CLooker

Untitled

Feb 2nd, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.hackerrank.com/challenges/sherlock-and-squares/problem
  2.  
  3. const squares = (a, b) => {
  4.     const first = Math.ceil(Math.sqrt(a));
  5.     const last = Math.floor(Math.sqrt(b));
  6.     return Array.from(Array(last - first + 1)).reduce((counter, _, index) => (
  7.       Number.isInteger(index + first) ? ++counter : counter
  8.     ), 0);
  9. }
  10.  
  11. function squares(a,b) {
  12.     const first = Math.ceil(Math.sqrt(a));
  13.     const last = Math.floor(Math.sqrt(b));
  14.     let counter = 0;
  15.     for (let i = first; i <= last; i++) {
  16.         if(Number.isInteger(i)) {
  17.             ++counter;
  18.         }
  19.     }
  20.     return counter;    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement