Issue with Code in Salesforce Interview Questions
I'm having a problem with a code snippet on the Salesforce Interview Questions page online: https://www.interviewbit.com/salesforce-interview-questions/. I've been attempting to solve the problem but I'm having difficulty understanding the logic behind the code. The code I'm working on is: //Create a function to take in an array of integers and return an object with the count of each integer function countIntegers(arr) { let resultObj = {}; for (let i = 0; i < arr.length; i++) { let currNum = arr[i]; if (resultObj[currNum] === undefined) { resultObj[currNum] = 1; } else { resultObj[currNum] += 1; } } return resultObj; } I understand the code but I'm having difficulty understanding how the logic works, and how to apply it to the problem. I would really appreciate any help or advice on how to approach the problem. Thanks!