Jump to content

~Code&Anime~

Members
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

~Code&Anime~'s Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. function selectAndList(propertyName, inputArr) { const propertyArr = []; inputArr.map(function(item) { propertyArr.push(item[propertyName]); }); return propertyArr; } function countOccurences(propertyArr, value){ const values =propertyArr.filter(function(prop){ return prop==value }) return values.length } function countOccurences(propertyArr){ const map=new Map() propertyArr.map(function(val){ if(map.has(val)){ map.set(val, map.get(val)+1) }else{ map.set(val, 0) } }) return map } Apologies for this previous misunderstanding. I have rewritten my code in addition as to not use arrow functions as you mentioned you are not familiar with this. I thought it best to mention this as this may be useful when looking up info online. This is how such works for information, this was introduced in ES6: function myFunc(val){ } const myFunc = (val)=>{ } You would call both with myFunc(val), this does not change. also you should use const and let instead of var, var is defined globally, even when within a function. I have rewritten the function to reduce time complexity. There is no need to create multiple arrays. I have also defined a function to count occurences for a given property value
  2. Yes but it seems that all the values for a given property are pudhed into an array, then the occurences are counted. This isn't very efficient. Edit: just realized i misunderstood the function. Will get back tomorrow.
  3. Your given code was quite hard to follow, I assume this code is supposed to count the number of property occurences of a given property for an array of objects? const countOccurences=(property, arr)=>{ let count=0 arr.map(item=>{ if(item.hasOwnProperty(property){ count++ } }) return count }
  4. I found it useful to learn CSS grid layout and flexbox layout. Cleaner code. Flexbox has more browser support but grid tends to have cleaner code.
×
×
  • Create New...