function getWordLengths(str) {
return str.split(' ').map(words => words.length)
}
내 오류는
AssertionError: expected [ 0 ] to deeply equal []
+ expected - actual
-[
- 0
-]
+[]
t('returns [] when passed an empty string', () => {
expect(getWordLengths('')).to.eql([]);
});
it('returns an array containing the length of a single word', () => {
expect(getWordLengths('woooo')).to.eql([5]);
});
it('returns the lengths when passed multiple words', () => {
expect(getWordLengths('hello world')).to.eql([5, 5]);
});
다음과 같이 사용할 수 있습니다.
function getWordLengths(str) {
return str.length > 0 ? str.split(' ').map(words => words.length) : [];
}
console.log( getWordLengths(""));
console.log( getWordLengths("Hi") );
console.log( getWordLengths("Hi there how are you") );
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다