Time complexity of includes() function in JavaScript

前端 未结 2 762
一整个雨季
一整个雨季 2020-12-18 18:57

I have an array that contains some hash values of certain strings, I don\'t want duplicate values in my array so I use if logic like this

if(!a         


        
2条回答
  •  隐瞒了意图╮
    2020-12-18 19:46

    as my list is not sorted so i have create a dictionary and put values into it after checking if value present in it or not . Here in this dictionary my value and key are same .

    var   arrayOfHashMap = {};/*is a dictionary,arrayOfValue is a list*/
        if(arrayOfHashMap[hash_value] !=hash_value){
                                   arrayOfValue.push(hash_value); 
                                   arrayOfHashMap[hash_value]=hash_value;
                            }
    

    in this case I search values in o(1) time and put them in arrayOfValue

提交回复
热议问题