Problem: I needed to convert seconds to a time format easily read by humans. I thought a digital time format would give the best user experience. The filtered time would look something like this: 2h 46m 12s Solution: Here's a JavaScript function i created that solves our time format problem: function digitalClockTime (totalSeconds) { const hours = Math.floor(totalSeconds / 60 / 60) totalSeconds = (totalSeconds - (hours * 60 * 60)) const minutes = Math.floor(totalSeconds / 60) totalSeconds = (totalSeconds - (minutes * 60)) const seconds = totalSeconds const timeParts = [] if (hours) { timeParts.push(`${hours}h`) } if (minutes) { timeParts.push(`${minutes}m`) } if (seconds) { timeParts.push(`${seconds}s`) } return timeParts.join(' ') } console.log( digitalClockTime (5020)) I basically took the total seconds passed to digitalClockTime and calculated the rounded ho...
As a product developer, I tend to focus on developing complex solutions and often times forget about coding basics. I constantly write and deploy code, but It's common to get stuck in the product development rut of reusing pre-developed blocks of code throughout the system. In order sharpen my skills. I made it a goal to revisit popular coding exercises and see how I can solve them now that I have a few years of working experience. The fibonacci sequence came across my path once again! I've been asked how to calculate the sequence in past interviews, and it's fairly straight forward. For those not familiar, here's the sequence: 0 1 1 2 3 5 8 13 21 Essentially, the sum of the first two values is the third value...and the sum of the second and third value is the fourth value, and so on. There's a couple of ways to solve this problem. Solution #1 The n parameter is basically an index stopping point. In other words, how large do I want the array to be ? I set a def...