foo2(['a', 'b', 'a', 'a']);

//实现函数foo,返回一个新数组['a-1', 'b-1', 'a-2', 'a-3'] 


let arrd = ['a', 'b', 'a', 'a'];
let newArray = [];
//统计字符在数组里面的次数
function countIndex(arr, value) {
return arr.reduce((a, v) => v.split('-')[0] === value ? a + 1 : a, 1)
}
function foo(arr) {
console.log(arr)
arr.map((item) => {
let index = countIndex(newArray, item)
newArray.push(`${item}-${index}`)
})
}


foo(arrd)
console.log(newArray)