I've been doing new Array(52).join('a'); to make a string of 52 as, but I could have just used 'a'.repeat(52)... now I need to make a little commit to update that.
The other day I even ranted about how nice Python's 'a' * 52 would have been.
constfirst=newArray(2).join('a');console.log(first);// 'a'constsecond='a'.repeat(2);console.log(second);// 'aa'// new Array(52).join('a') will not print 52 a's, print 51 a'sconstaLength=newArray(52).join('a').length;console.log(aLength);// 51
Oops, you're right! Typo on my part :) For the sake of my E2E tests, I actually think repeat would be easier to read.
it('displays an error for too many characters',function(){relevantPage.middleInitial.sendKeys('a'.repeat(2));// clearly shows that 2 is considered too manyexpect(relevantPage.middleInitialTooLongMessage.getText()).toEqual('Middle initial is too long');});
repeatexists? :oI've been doing
new Array(52).join('a');to make a string of 52as, but I could have just used'a'.repeat(52)... now I need to make a little commit to update that.The other day I even ranted about how nice Python's
'a' * 52would have been.They are not same
Oops, you're right! Typo on my part :) For the sake of my E2E tests, I actually think
repeatwould be easier to read.Actually repeat is easy to read
If you want to make string of 52 a's with repeat is so easy
Array index starts from 0 which means it will print 52 times.
Yass, and since join acts as 'glue', using 'a' as glue for 52 nothings will print 'a' 51 times. Give it a try ;)