알고리즘 64 - Stringy Strings

tamagoyakii·2021년 10월 20일
0

알고리즘

목록 보기
64/89

Q.

write me a function stringy that takes a size and returns a string of alternating '1s' and '0s'.

the string should start with a 1.

a string with size 6 should return :'101010'.

with size 4 should return : '1010'.

with size 12 should return : '101010101010'.

The size will always be positive and will only use whole numbers.

A)

function stringy(size) {
  let ret = '';
  for (let i = 0; i < size; i++) ret += i % 2 === 0 ? '1' : '0'
  return ret;
}

0개의 댓글