function alphabetSubsequence(str) {
// write code here.
// def not the most efficient way of doing this I'm sure
let splitString = str.split("");
let charCodeArray = splitString.map(item => item.charCodeAt());
let truthyArray = [];
for (let i = 0; i < charCodeArray.length; i++) {
if (charCodeArray[i] < charCodeArray[i+1]) {
truthyArray.push(true);
} else if (charCodeArray[i] === charCodeArray[i+1]) {
truthyArray.push(false);
} else if (!charCodeArray[i+1]) {
truthyArray.push(true);
} else {
truthyArray.push(false);
}
}
if (truthyArray.includes(false)) return false;
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);
});
});