본문 바로가기
알고리즘/Codewars

[Codewars] Count the Monkeys! (8 kyu) / JavaScript

by fluss 2023. 2. 18.

https://www.codewars.com/kata/56f69d9f9400f508fb000ba7

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1.

As a good parent, you will sit and count with him. Given the number (n), populate an array with all numbers up to and including that number, but excluding zero.

 

For example(Input --> Output):

10 --> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 1 --> [1]
 

코드

function monkeyCount(n) {
  return Array(n).fill().map((v, i) => i + 1);
}

댓글