scrimba
Note at 0:31
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

AboutCommentsNotes
Note at 0:31
Expand for more info
main.js
run
preview
console
function alphabetSubsequence(str) {
// write code here.
let a =[...str] //convert str to arr to feed to set func
let b = new Set(a) //removes duplicates
//checks if the size of set and size of original string are same if not that means it has duplicate
if(a.length === b.size){
//console.log(a)
for (let i=1; i < a.length; i++){
// first do negative check if not there that means its positve
if(a[i].charCodeAt(0) < a[i-1].charCodeAt(0)){
console.log(a[i].charCodeAt(0))
console.log(a[i-1].charCodeAt(0))
return false
}
}
return true
}
else {
return false
}

}

/**
* 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);
});
it('returns false when no duplicates and is NOT in ascending a - z order ', () => {
// arrange
const str = 'hjoi';

// act
const result = alphabetSubsequence(str);

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

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




Console
105
,
111
,
"result 4: "
,
false
,
"result 3: "
,
true
,
"result 2: "
,
false
,
"result 1: "
,
false
,
/index.html?spec=
LIVE