Explorer
project
boot.js
index.html
index.js
jasmine-html.js
jasmine.css
jasmine.js
main.js
Dependencies
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
/** Throws if you pass anything other than a string of length >= 1
* @param String of alphabets. Case insensitive "aBc" === "abc"
* @returns Boolean true/false
*/
function alphabetSubsequence(str) {
if (typeof str !== "string" || !str.length) {
throw new Error("Invalid input");
}
const lowerCaseStr = str.toLowerCase();
const lastIndex = str.length - 1;
for (let i = 0; i < lastIndex; i++) {
const thisCharCode = lowerCaseStr.charCodeAt(i);
const nextCharCode = lowerCaseStr.charCodeAt(i + 1);
if (nextCharCode <= thisCharCode) {
return false;
}
if (thisCharCode < 97 || 122 < thisCharCode) {
return false;
}
}
const lastCharCode = lowerCaseStr[lastIndex];
return !(lastCharCode < 97 || lastCharCode > 122);
}
/**
* 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);
});
});