Generation

generate functionMon, 08 May 2023

count repeated elements of an array

Script var count = {}; var input = ['a', 'b', 'c', 'b', 'c', 'c', 'c', 'd']; for (var i=0; i<input.length; i++) { var num = input[i]; count[num] = count[num] ? count[num]+1 : 1; }

Questions about programming?Chat with your personal AI assistant