function alphabetSubsequence(str) {
// write code here.
//Split it so we can map through the array
const stringToArray = str.split('')
const output = stringToArray.map((e, index) => {
// Check if next strings index UTF-16 code is the same or greater than the previous
return str.charCodeAt(index) >= str.charCodeAt(index + 1)
//Return false on each element if it isnt following ABC in correct order
? false
: true
})
//So now output should store an array with:
// "false, false, true", or
// "true, true, true"
//So if all of the elements are true int he array, then we return true
return output.every(element => element === true)
}
alphabetSubsequence('yookmokk')
/**
* 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);
});
});