DEV Community

Discussion on: whats the worst program you can make for squaring a number.

Collapse
 
ncpa0cpl profile image
ncpa0cpl • Edited
const square = (n: number) => {
  n = Math.abs(n);
  while(true) {
    const result = Math.random() * Number.MAX_SAFE_INTEGER;
    if(result % n === 0) {
      let c = result;
      let d = 0;
      while(true) {
        c -= n;
        d++;
        if(c === 0) break;
      }
      if(d === n) return result;
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

DISCLAIMER
This for all I know may crash the browser tab it's running in.