Lonely Integer

  • + 0 comments

    in JavaScript:

    function lonelyinteger(a) {
        const numOfIncidents = a.reduce((obj, int) => {
            obj[int] = (obj[int] || 0) + 1;
            return obj;
        }, {});
        
        for (let key in  numOfIncidents) {
             if (numOfIncidents[key] === 1){
                 return parseInt(key);
             }
         }
     }