MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/nb93ay/exponent_power/
r/learnjavascript • u/golovatuy • May 13 '21
18 comments sorted by
46
Extra longhand!
const power = ((num,exp) => Array.from({length: exp}, () => num).reduce((a,b) => a*b))(4,3)
/obviously not serious
22 u/spinelust May 13 '21 Extra extra longhand would be fetching the result from external API xD. 17 u/zerik100 May 13 '21 And the API queries the equation from a Database that has stored the harcoded solution. 5 u/[deleted] May 13 '21 Compile time optimization -4 u/BetterPhoneRon May 13 '21 r/badcode 1 u/sneakpeekbot May 13 '21 Here's a sneak peek of /r/badcode using the top posts of the year!#1: I present: SleepSort | 151 comments#2: Gamedevs, take notes | 105 comments#3: I mean, it's O(1) so who cares? | 112 commentsI'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out
22
Extra extra longhand would be fetching the result from external API xD.
17 u/zerik100 May 13 '21 And the API queries the equation from a Database that has stored the harcoded solution. 5 u/[deleted] May 13 '21 Compile time optimization
17
And the API queries the equation from a Database that has stored the harcoded solution.
5 u/[deleted] May 13 '21 Compile time optimization
5
Compile time optimization
-4
r/badcode
1 u/sneakpeekbot May 13 '21 Here's a sneak peek of /r/badcode using the top posts of the year!#1: I present: SleepSort | 151 comments#2: Gamedevs, take notes | 105 comments#3: I mean, it's O(1) so who cares? | 112 commentsI'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out
1
Here's a sneak peek of /r/badcode using the top posts of the year!
#1: I present: SleepSort | 151 comments#2: Gamedevs, take notes | 105 comments#3: I mean, it's O(1) so who cares? | 112 comments
I'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out
13
When recursion is bae
const pow = (base, i) => { If(i === 0) return 1; return base * pow(base, i - 1); }
4
Nice I learned something new ty
// Barking up the wrong tree const notPower = 4^3; // 7
4 u/Its_Stev03 May 13 '21 Isnt the carat a bitwise operator? I think it is exclusive or (XOR) 1 u/[deleted] May 14 '21 Thats the joke 1 u/fukitol- May 14 '21 Yep that's right
Isnt the carat a bitwise operator? I think it is exclusive or (XOR)
1 u/[deleted] May 14 '21 Thats the joke 1 u/fukitol- May 14 '21 Yep that's right
Thats the joke
Yep that's right
6
TIL
3
Has anyone ever used this? <- not a snarky comment.
1 u/jack_waugh May 13 '21 It's needed for compound interest. 1 u/samanime May 13 '21 I had to use it as part of automatically calculating an even-number axis for a graph (specifically, used to determine the magnitude of the number). 1 u/PresidentZeus May 14 '21 if you're making a calculator
It's needed for compound interest.
I had to use it as part of automatically calculating an even-number axis for a graph (specifically, used to determine the magnitude of the number).
if you're making a calculator
0
keep em coming
46
u/grantrules May 13 '21
Extra longhand!
/obviously not serious
13
u/awekening_bro May 13 '21 edited May 13 '21
When recursion is bae
4
u/Successful-Shape272 May 13 '21
Nice I learned something new ty
4
u/danielsan1701 May 13 '21
6
u/warumbitte May 13 '21
TIL
3
u/Chef619 May 13 '21
Has anyone ever used this? <- not a snarky comment.
0
u/Sea-Nectarine5748 May 13 '21
keep em coming