Right idea, wrong implementation sort of thing? Tried both separate cases where ( <bL.length) and tot += bL[bL.length -1] after … This is the version that passed m8…
I agree that the complexity would be reduced slightly… I’ll debug it and see if it runs. If it does pass all states,I’ll let you know. Otherwise, posting the debugged, complete code on similar basis. Regardless if such works, I agree that it wasn’t the most efficient method I was using. Always room to improve the method, but since it didn’t exceed O(n+k) I didn’t really care to improve it… I get that it’s WCS complexity shouldn’t exceed O(1) but still
In any case, since this challenge has no solutions, I’d be happy to add one or both of ours.
Mine would need a brief explanation.
For yours, I’d ask for a brief explanation, the -1 issue sorted out, a bit clearer variable names, and triming a bit of extra calculation in your for loop.
Yeah, I come from C/Fortran background so I appreciate the desire for brevity. But after spending time in languages with more verbose conventions, such as Julia and Rust, I’ve grown fond of using full words when able. Personal preference, I suppose.
The cool thing with JS is that production code often gets ‘uggified’ and the variable names collapsed to short incomprehensible names to save space, so we’re free to use as big of names as we like for readability and it won’t effect end code size.
The description makes it sound like you are supposed to create 3 function for each functionality (half/double/check if even). I also think using multiplication in the code kind of defeats the purpose of doing multiplication without using multiplication.
Yeah, I thought about making my version use those functions, but I was coding on my phone and feeling lazy. That’s such a bizarre requirement since those functions are so basic and only needed in one place in the code.
Edit: I’ve updated my solution to reflect this strange requirement.
I’m still not wild about making a data structure to hold the left and right values instead of just adding as you go. Less efficient that way.