ruby on rails - Check if a sentence includes any words in an array -


splitdescription = work.workdescription.downcase.split(' ')  keywords = ['teamwork', 'developed', 'enhanced', 'transformed', 'achieved','grew', 'introduced', 'project', 'awarded',              'planned','supervised','created','designed','discovered','evaluated','promoted','represented','completed',              'devised','liaised','controlled','researched','organised','achieved','managed','analysed','assessed','conducted',              'solved','responsible for','responsibilities']  splitdescription.select {|word| word.include?(keywords)}.each |word|     new_score += 0.5 end 

i have splitdescription splits , store description.

i want see if of keywords in splitdescription , each keyword in splitdescription new_score goes 0.5.

im trying code @ moment not work correctly.

you there:

splitdescription.select { |word| keywords.include?(word) } 

since here keywords array lookup single word in.

more robust solution be:

new_score += 0.5 * (splitdescription & keywords).size 

the latter intersect keywords array , splitted description, calculates size of intersection , increase score value divided two.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -