📅  最后修改于: 2023-12-03 15:01:37.059000             🧑  作者: Mango
Are you a JavaScript programmer who loves to solve challenges and optimize your code to its absolute minimum? Then CodeGolf is the perfect platform for you!
CodeGolf is a website that challenges programmers to solve problems by writing the shortest code possible. It's a fun way to improve your coding skills, learn new tricks, and compete with other developers from around the world.
CodeGolf offers a set of challenges with specific requirements and constraints, including input and output formats, runtime limitations, and more. Participants are tasked with writing a program that solves the problem as efficiently as possible, in terms of code length.
Each challenge has a point value associated with it, and the higher the value, the more difficult the challenge. Participants can earn points by submitting their solutions, which are then evaluated by a code scanner that checks for syntax errors, runtime issues, and overall code length.
The goal is to earn as many points as possible by submitting the shortest code solutions to each challenge. The top-scoring participants are featured on the site's leaderboard, and can earn prizes and recognition for their achievements.
Here's an example of a challenge from CodeGolf:
Problem Statement
Write a program that takes an input string and returns the first non-repeated character in the string. If no such character is found, the program should return "-1".
Input
The input string will consist of only lowercase English letters.
Output
The output should be a single character, or "-1" if no non-repeated character is found.
Constraints
The program should not exceed 100 characters in length.
Here's a short JavaScript solution:
f=s=>s.split('').filter(c=>s.indexOf(c)==s.lastIndexOf(c))[0]||'-1'
This solution uses arrow functions, array methods, and a ternary operator to keep the code concise and readable, while still solving the problem efficiently.
CodeGolf is a great way to challenge yourself, improve your coding skills, and connect with other developers. So, are you up for the challenge? Head over to the site and start coding!