We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
输入 '1, 2, 3, 5, 7, 8, 10' 输出 '1~3, 5, 7~8, 10'
如果连续数字的话,就取连续的第一个数和最后一个数,中间用~隔开。如果不连续就用,隔开。
The text was updated successfully, but these errors were encountered:
issues
const nums1 = [1, 2, 3, 5, 7, 8, 10]; function simplifyStr(num) { var result = []; var temp = num[0] num.forEach((value, index) => { if (value + 1 !== num[index + 1]) { if (temp !== value) { result.push(`${temp}~${value}`) } else { result.push(`${value}`) } temp = num[index + 1] } }) return result; } console.log(simplifyStr(nums1).join(','))
Sorry, something went wrong.
No branches or pull requests
输入 '1, 2, 3, 5, 7, 8, 10' 输出 '1~3, 5, 7~8, 10'
如果连续数字的话,就取连续的第一个数和最后一个数,中间用~隔开。如果不连续就用,隔开。
The text was updated successfully, but these errors were encountered: