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

[Codewars] Enumerable Magic #25 - Take the First N Elements (8 kyu) / JavaScript

by fluss 2023. 3. 16.

https://www.codewars.com/kata/545afd0761aa4c3055001386

 

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:

Create a function that accepts a list/array and a number n, and returns a list/array of the first n elements from the list/array.

If you need help, here's a reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

 

코드

function take(arr, n) {
  return arr.slice(0, n);
}

댓글