🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of The-F00L

The-F00L's solution

to Isogram in the CFML Track

Published at May 06 2021 · 0 comments
Instructions
Test suite
Solution

Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

  • lumberjacks
  • background
  • downstream
  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.


To run the code in this exercise, you will only need to have CommandBox CLI installed. This binary runs CFML code from the command line.

To run the tests, cd into the exercise folder and run the following:

box task run TestRunner
# Or start up a test watcher that will rerun when files change
box task run TestRunner --:watcher

The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the BDD style which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:

https://testbox.ortusbooks.com/content/

Source

Wikipedia https://en.wikipedia.org/wiki/Isogram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

IsogramTest.cfc

component extends="testbox.system.BaseSpec" {

	function beforeAll(){
	  SUT = createObject( 'Isogram' );
	}

	function run(){
	
		describe( "My Isogram class", function(){			

			describe( 'Check if the given string is an isogram', function(){

				it( 'empty string', function(){
					expect( SUT.isIsogram( input='' ) ).toBeTrue();
				});

				it( 'isogram with only lower case characters', function(){
					expect( SUT.isIsogram( input='isogram' ) ).toBeTrue();
				});

				it( 'word with one duplicated character', function(){
					expect( SUT.isIsogram( input='eleven' ) ).toBeFalse();
				});

				it( 'longest reported english isogram', function(){
					expect( SUT.isIsogram( input='subdermatoglyphic' ) ).toBeTrue();
				});

				it( 'word with duplicated character in mixed case', function(){
					expect( SUT.isIsogram( input='Alphabet' ) ).toBeFalse();
				});

				it( 'hypothetical isogrammic word with hyphen', function(){
					expect( SUT.isIsogram( input='thumbscrew-japingly' ) ).toBeTrue();
				});

				it( 'isogram with duplicated hyphen', function(){
					expect( SUT.isIsogram( input='six-year-old' ) ).toBeTrue();
				});

				it( 'made-up name that is an isogram', function(){
					expect( SUT.isIsogram( input='Emily Jung Schwartzkopf' ) ).toBeTrue();
				});

				it( 'duplicated character in the middle', function(){
					expect( SUT.isIsogram( input='accentor' ) ).toBeFalse();
				});

			});

		});
		
	}
 
}

SolutionTest.cfc

component extends="IsogramTest" {

	function beforeAll(){
	  SUT = createObject( 'Solution' );
	}

}
/**
* Your implmentation of the Isogram exercise
*/
component {

	/**
	* @returns
	*/
	function isIsogram( input ) {
		// sentence=listToArray(lCase(refind(input,"[A-Za-z]","","all")),"").sort("text","asc");
		sentence=reMatch("[a-z]",lCase(input)).sort("text","asc");
		for (i = 1; i < len(sentence); i++) {
			if (i+1<=len(sentence)){
				if (sentence[i]==sentence[i+1]){
					return false;
				}
			}
		}
		return true;
	}

}

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?