• Jump To … +
    abbreviations.js adjectives.js convertables.js dates.js demonyms.js firstnames.js honourifics.js irregular_nouns.js irregular_verbs.js misc.js multiples.js numbers.js organisations.js phrasal_verbs.js places.js uncountables.js verbs.js fns.js index.js lexicon.js negate.js passive_voice.js contractions.js fancy_lumping.js grammar_rules.js parts_of_speech.js phrasal_verbs.js tagger.js word_rules.js question.js sentence.js statement.js tense.js adjective.js to_adverb.js to_comparative.js to_noun.js to_superlative.js adverb.js to_adjective.js is_acronym.js article.js date.js date_rules.js is_date.js parse_date.js is_plural.js is_uncountable.js noun.js is_organisation.js organisation.js gender.js is_person.js parse_name.js person.js is_place.js place.js pluralize.js pronoun.js singularize.js is_value.js numbers.js to_number.js units.js value.js term.js conjugate.js from_infinitive.js predict_form.js suffix_rules.js to_actor.js to_infinitive.js negate.js verb.js sentence_parser.js text.js
  • to_superlative.js

  • ¶

    turn ‘quick’ into ‘quickest’

    'use strict';
    const convertables = require('../../data/convertables.js');
    
    const to_superlative = function(str) {
      const irregulars = {
        'nice': 'nicest',
        'late': 'latest',
        'hard': 'hardest',
        'inner': 'innermost',
        'outer': 'outermost',
        'far': 'furthest',
        'worse': 'worst',
        'bad': 'worst',
        'good': 'best'
      };
    
      const dont = {
        'overweight': 1,
        'ready': 1
      };
    
      const transforms = [{
        'reg': /y$/i,
        'repl': 'iest'
      }, {
        'reg': /([aeiou])t$/i,
        'repl': '$1ttest'
      }, {
        'reg': /([aeou])de$/i,
        'repl': '$1dest'
      }, {
        'reg': /nge$/i,
        'repl': 'ngest'
      }];
    
      const matches = [
        /ght$/,
        /nge$/,
        /ough$/,
        /ain$/,
        /uel$/,
        /[au]ll$/,
        /ow$/,
        /oud$/,
        /...p$/
      ];
    
      const not_matches = [
        /ary$/
      ];
    
      const generic_transformation = function(s) {
        if (s.match(/e$/)) {
          return s + 'st';
        }
        return s + 'est';
      };
    
      for (let i = 0; i < transforms.length; i++) {
        if (str.match(transforms[i].reg)) {
          return str.replace(transforms[i].reg, transforms[i].repl);
        }
      }
    
      if (convertables.hasOwnProperty(str)) {
        return generic_transformation(str);
      }
    
      if (dont.hasOwnProperty(str)) {
        return 'most ' + str;
      }
    
      if (irregulars.hasOwnProperty(str)) {
        return irregulars[str];
      }
      for (let i = 0; i < not_matches.length; i++) {
        if (str.match(not_matches[i])) {
          return 'most ' + str;
        }
      }
    
      for (let i = 0; i < matches.length; i++) {
        if (str.match(matches[i])) {
          return generic_transformation(str);
        }
      }
      return 'most ' + str;
    };
  • ¶

    console.log(to_superlative(“great”))

    module.exports = to_superlative;