scrimba
Note at 1:06
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:06
AboutCommentsNotes
Note at 1:06
Expand for more info
main.js
run
preview
console
function alphabetSubsequence(str) {
for (let i = 0; i < str.length; i++){
// Check if not in alphabetical order
if (str.charCodeAt(i + 1) < str.charCodeAt(i)) {
return false;
}
// Check if there are duplicate letters
else if (str.charCodeAt(i) == str.charCodeAt(i + 1)) {
return false;
}
// Continue checking letters till end of string
else if (i < str.length - 1){
continue;
}
// Sequence in alphabetical order
else {
return true;
}
}
}

/**
* 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
"a"
,
"c"
,
"e"
,
"result 3: "
,
true
,
"e"
,
"f"
,
"result 1: "
,
false
,
"c"
,
"d"
,
"result 2: "
,
false
,
/index.html
LIVE