Time to completion: ~12m
Submitted code:
function plusMinus(arr: number[]): void {
// Write your code here
const arraySize = parseInt(inputLines[0])
const elementString = inputLines[1]
const elements = elementString.split(" ")
let neg = 0
let pos = 0
let zer = 0
for (const e of elements){
let n = parseInt(e)
if (n>0) pos++
if (n<0) neg++
if (n===0) zer++
}
console.log((pos/arraySize).toFixed(6))
console.log((neg/arraySize).toFixed(6))
console.log((zer/arraySize).toFixed(6))
}
Stuff I had to look up:
toFixed()
switch
statements, but ended up not using them.
Takeaways I should probably work a bit faster and more pragmatically. It’s hard to totally sum this up - it’s really just efficiency and risk management, and avoiding indulgences, like trying to use the switch statement, or getting sidetracked. Poverty mindset…?