DEV Community

Discussion on: Square a number: awful answers only

Collapse
reobin profile image
Robin Gagnon

Compact solution that passes all tests:

function square(value) {
  if (value === 4) {
    return 4 + 4 + 4 + 4;
  }
  if (value === 16) {
    return 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16;
  }
  if (value === 51) {
    return 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51 + 51;
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
snorkypie profile image
Steeve Lennmark

Came here to submit this exact version, good job!

Collapse
kidsmohamed profile image
kidsmohamed

thanks for your help

Collapse
v6 profile image
πŸ¦„N BπŸ›‘

Ohhh, boy. I needed that laugh, today. Thanks.

Collapse
codeandclay profile image
Oliver

You should add a to-do comment for each unimplemented number.

Collapse
reobin profile image
Robin Gagnon

Definitely will add that to the to-do list!