6 kyu

T.T.T.29: Similarity evaluation of two strings

Description:

Task

Complete function similarityEvaluation() that accepts two string arguments s1 and s2. return a string value like this: 100%.

How to evaluate the similarity of two strings? Please follow these rules:

Rules

    1. Whole principle
    • Same length:                                                           +10%
      Example:   "abc" "xyz"
    • Same beginning and ending                            +20%
      (Both of two strings should has at least two chars)
      Example:   "where" "whole"(starting with w and ending with e)
    • Same number of letters                                        +5%
      Example:   "were1" "wire23"(four letters, number of letters should > 0)
    • Same number of digits                                          +5%
      Example:   "abc12" "d34"(two digits, number of digits should > 0)
    • Same number of words                                        +5%
      Example:   "abc def" "def abc"(Separated by spaces, number of words should > 1)
    • Same ASCII ascending or descending             +10%
      Example:   "abc" "def"(Whole ascending) 987 cba (Whole descending)
    • All are palindrome string                                  +10%
      Example:   "aba" "defed"(string length should > 1)
    • The sum of ASCII values are equal                 +20%
      Example:   "aB" "Ab"(97 + 66 == 65 + 98)
    • s1 reversed same as s2                                        +20%
      Example:   "aBc" "cbA"(ignore case)
    • Two strings are composed of a single identical character       +40%
      Example:   "aa" "aaaa"
    • The difference between the two strings is only one character       +30%
      (The same characters can be in different positions)
      Example:   "abcde" "abcdf","abcd" "abfcd","abcde" "fdcba"
    1. Individual principle
    • Contains the same letters                            +2-10% (Each letter +2%, no more than 10%)
      Example:   "ab123" "a456b"(both contains letters a and b)

    • Contains the same digits                              +2-10% (Each digit +2%, no more than 10%)
      Example:   "a1b2c3" "1x2y3z"(both contains digits 1, 2 and 3)

    • Contains the same other characters       +4-20% (Each character +4%, no more than 20%)
      Example:   "hello!" "world!"(both contains character !)

      • Note: When counting the same characters, the duplicate characters should be counted. For example, 111 and 111111 have 3 same digits, not 1, also not 6.
    1. Special principle
    • In any case, two exactly the same string should return "100%".
      Example:   "" "","1" "1"
    • If they are not two exactly the same string, the overall score should not exceed 99%. if exceed, return "99%".
    • If one of s1,s2 is an empty string "", should return "0%".

Examples

similarityEvaluation("abc","123abc") === "21%"
same number of letters: --> +5
same ASCII ascending or descending : --> +10
Whole score = 15%
Contains the same letters:3 --> +6
Total score = 21%  

similarityEvaluation("five","file") === "71%"
same length: --> +10
same start&end: --> +20
same number of letters: --> +5
The difference between the two strings is only one character: --> +30
Whole score = 65%
Contains the same letters:3 --> +6
Total score = 71%  

similarityEvaluation("web link","website link") === "39%"
same start&end: --> +20
same number of words: --> +5
Whole score = 25%
Contains the same letters:7 --> +10
Contains the same other characters:1 --> +4
Total score = 39%  

similarityEvaluation("abc","CBA") === "35%"
same length: --> +10
same number of letters: --> +5
s1 reversed same as s2: --> +20
Whole score = 35%
Total score = 35% 

similarityEvaluation("Help me!!!!!123457","Help me!!!!!123456") === "95%"
same length: --> +10
same number of letters: --> +5
same number of digits: --> +5
same number of words: --> +5
The difference between the two strings is only one character: --> +30
Whole score = 55%
Contains the same letters:6 --> +10
Contains the same digits:5 --> +10
Contains the same other characters:6 --> +20
Total score = 95%  

similarityEvaluation("111AAA     AAA111","111AAA      AAA111") === "99%"
same start&end: --> +20
same number of letters: --> +5
same number of digits: --> +5
same number of words: --> +5
All are palindrome string: --> +10
The difference between the two strings is only one character: --> +30
Whole score = 75%
Contains the same letters:6 --> +10
Contains the same digits:6 --> +10
Contains the same other characters:5 --> +20
Total score = 99%  

similarityEvaluation("abcde","abcdf") === "63%"
same length: --> +10
same number of letters: --> +5
same ASCII ascending or descending : --> +10
The difference between the two strings is only one character: --> +30
Whole score = 55%
Contains the same letters:4 --> +8
Total score = 63%  

similarityEvaluation("abcd","abcdf") === "48%"
same ASCII ascending or descending : --> +10
The difference between the two strings is only one character: --> +30
Whole score = 40%
Contains the same letters:4 --> +8
Total score = 48%  

similarityEvaluation("abcde","abdde") === "73%"
same length: --> +10
same start&end: --> +20
same number of letters: --> +5
The difference between the two strings is only one character: --> +30
Whole score = 65%
Contains the same letters:4 --> +8
Total score = 73%  

similarityEvaluation("aa","aaaa") === "74%"
same start&end: --> +20
All are palindrome string: --> +10
Two strings are composed of a single identical character: --> +40
Whole score = 70%
Contains the same letters:2 --> +4
Total score = 74% 

similarityEvaluation("  ","   ") === "99%"
same start&end: --> +20
All are palindrome string: --> +10
Two strings are composed of a single identical character: --> +40
The difference between the two strings is only one character: --> +30
Whole score = 100%
Contains the same other characters:2 --> +8
Total score = 99%  

similarityEvaluation("","abc") === "0%"
one of s1,s2 is empty string: --> 0%

similarityEvaluation("","") === "100%"
s1 equals to s2: --> 100%

similarityEvaluation("a","a") === "100%"
s1 equals to s2: --> 100%
Puzzles
Games

Stats:

CreatedAug 11, 2016
PublishedAug 11, 2016
Warriors Trained150
Total Skips3
Total Code Submissions547
Total Times Completed33
JavaScript Completions33
Total Stars12
% of votes with a positive feedback rating91% of 17
Total "Very Satisfied" Votes15
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • ZED.CWT Avatar
Ad