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

[Codewars] Testing 1-2-3 (7 kyu) / JavaScript

by fluss 2023. 2. 8.

https://www.codewars.com/kata/54bf85e3d5b56c7a05000cf9

 

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:

Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.

Write a function which takes a list of strings and returns each line prepended by the correct number.

The numbering starts at 1. The format is n: string. Notice the colon and space in between.

 

Examples: (Input --> Output)

[] --> []
["a", "b", "c"] --> ["1: a", "2: b", "3: c"]
 

코드

var number=function(array){
  return array.map((el, i) => i + 1 + ": " + el);
}

댓글