-2

Im trying to convert the script below to a normal function, but fail to understand how.

The script counts the numbers of instances (model) in a Array (productList.Lockers) and appends it to a target div.

productList.Lockers.forEach(o => $('#' + o.model).siblings('#modelcount').text((i, t) => (  parseInt(t, 10) || 0) + 1 ));
var modelCount = document.getElementById('allcount');
modelCount.innerHTML = productList.Lockers.length;
user3344734
  • 707
  • 1
  • 4
  • 13
  • 1
    are you converting the arrow functions into normal functions or the whole script (which wouldn't make sense)? is this homework? – Dave Cousineau Feb 21 '20 at 06:54

1 Answers1

1

Seems easy:

productList.Lockers.forEach(function(o) {
  return $('#' + o.model).siblings('#modelcount').text(function(i, t) {
    return (parseInt(t, 10) || 0) + 1
  })
})
connexo
  • 41,035
  • 12
  • 60
  • 87