Code Golf · #64 · 2026-06-07
Truncate a string
Difficulty 2/3 · JavaScript
How to play
Write a JavaScript function body that passes all test cases using the fewest characters. Run against examples first, then submit for the full test suite. Eagle < Birdie < Par.
Given [string, maxLength], truncate to maxLength chars and add "..." if it was longer. If not longer, return as-is.
Examples
f(["Hello World",5]) → Hello...
f(["Hi",10]) → Hi
Loading your progress...
Your code (function body — receives input)
function(input) { 0 chars
}
Write the shortest JavaScript function body that passes all tests · Back to hub