The challenge Given an array of positive integers, return the number with the most digits. If two numbers have the same number of digits, return the first one in the array. Examples: findLongest([1, 10, 100]); // → 100 findLongest([9000, 8, 800]); // → 9000 findLongest([8, 900, 500]); // → 900 This puzzle is asked in JavaScript-flavoured Codewars, HackerRank, and front-end interviews. The trick is the tie-breaker rule — the first occurrence wins. Solution 1: reduce() with a digit count The cleanest functional approach in JavaScript:
No comments yet. Log in to reply on the Fediverse. Comments will appear here.