188 days ago · Tech · hide · Fediverse post

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:

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town