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

[Codewars] validate code with simple regex (8 kyu) / JavaScript

by fluss 2023. 4. 27.

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

 

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:

Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return true if so. Return false otherwise.

You can assume the input will always be a number.

 

코드

function validateCode (code) {
  return (/^[123]/).test(code);
}

댓글