scrimba
Note at 1:40
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 1:40
AboutCommentsNotes
Note at 1:40
Expand for more info
main.js
run
preview
console
function alphabetSubsequence(str) {
//set an alphabet array to check order against...
const alphabet = ['a', 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
//return vaue is false by default;
let returnValue = false;

for (i = 1; i < str.length; i++){
let char = str.charAt(i);
let lastChar = str.charAt(i-1);
if( alphabet.indexOf(char) > alphabet.indexOf(lastChar)){
//mark the return value as true, if the whole loop is successful the true will be returned
returnValue = true;
}else {
returnValue = false;
//end for loop and exit once the first false is found;
break;
}}
return returnValue;
}



/**
* Test Suite
*/
describe('alphabetSubsequence()', () => {
it('returns false when it has duplicate letters', () => {
// arrange
const str = 'effg';

// act
const result = alphabetSubsequence(str);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(false);
});

it('returns false when NOT in ascending a - z order', () => {
// arrange
const str = 'cdce';

// act
const result = alphabetSubsequence(str);

// log
console.log("result 2: ", result);

// assert
expect(result).toBe(false);
});

it('returns true whenno duplicates and is ascending a - z order ', () => {
// arrange
const str = 'ace';

// act
const result = alphabetSubsequence(str);

// log
console.log("result 3: ", result);

// assert
expect(result).toBe(true);
});
});
Console
"result 3: "
,
true
,
"result 2: "
,
false
,
"result 1: "
,
false
,
/index.html
LIVE