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

[Codewars] Fake Binary (8 kyu) / JavaScript

by fluss 2023. 1. 19.

https://www.codewars.com/kata/57eae65a4321032ce000002d

 

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:

Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string.

Note: input will never be an empty string

 

코드

function fakeBin(x){
  return x.split('').map(el => el < 5? '0' : '1').join('');
}

댓글