Skip to main content
added 17 characters in body
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (ES6), 71

Beating @ETHProductions while he does not see my hintBeating @ETHProductions while he does not see my hint. He saw it.

x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

Test

f=x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

function test() { n=+I.value, O.textContent = n + ' -> ' + f(n) }

test()
<input id=I type=number value=19557 oninput=test()>
<pre id=O></pre>

Test

#JavaScript (ES6), 71

Beating @ETHProductions while he does not see my hint.

x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

Test

f=x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

function test() { n=+I.value, O.textContent = n + ' -> ' + f(n) }

test()
<input id=I type=number value=19557 oninput=test()>
<pre id=O></pre>

Test

#JavaScript (ES6), 71

Beating @ETHProductions while he does not see my hint. He saw it.

x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

Test

f=x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

function test() { n=+I.value, O.textContent = n + ' -> ' + f(n) }

test()
<input id=I type=number value=19557 oninput=test()>
<pre id=O></pre>

Test

Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (ES6), 71

Beating @ETHProductions while he does not see my hint.

x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

Test

f=x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

function test() { n=+I.value, O.textContent = n + ' -> ' + f(n) }

test()
<input id=I type=number value=19557 oninput=test()>
<pre id=O></pre>

Test