Jump to content

~Code&Anime~

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by ~Code&Anime~

  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. On 8/13/2018 at 9:02 PM, iwato said:

    ~Code&Anime~:  I am not familiar with your syntax, and it is therefore difficult for me to comment on it, but it does appear to oversimplify the task.  Please correct me, if I am wrong.  

    The countOccurrence() function receives as input an array that appears as something akin to the following:

    
    Array [ "キャップチブ", "proposition", "Grammar Captive", "proposition", "文法", "Grammar Captive", "proposition", "Grammar Captive", "proposition", "文法" ]

    The elements of this array are the values of a property called target found in each of the objects of the initial inputArr of the external function named countValueFrequency().  The countOccurrence() function counts the number of times that each of these values occurs in newly formed array and returns the result in the following format.

    
    Array [ Object, Object, Object, Object ]

    for which each object is of the following form:

    count:  1
    value: "キャップチブ"

    count:  4
    value: 'proposition'

    etc.

    Although somewhat awkward, these resulting objects must then be converted into arrays, so that they can be fed into the wordcloud2.js script for the creation of a word cloud.

    Roddy

     

    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. 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...