/**
* Return the dominator of the given array.
*
* The dominator is the value that occurs in more than half of the elements of
* the given array.
*
* @param nums Array of numbers.
*
* @returns `-1` if there is no dominator.
*
* @example
* dominator([3,4,3,2,3,1,3,3]) → 3
* dominator([1,2,3,4,5]) → -1 // No val occurs more than half the array
*/functiondominator(nums:number[]):number{for(constitemofnewSet(nums)){if(nums.filter(i=>i===item).length>nums.length/2){returnitem;}}return-1;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript