每行输入一条文本,点击「执行」删除完全重复的行和空白行,随后复制或下载结果。保留首次出现的顺序,区分大小写;非空行的首尾空格会保留,并参与重复判断。
输入三行 Nuxt、Vue、Nuxt,得到两行 Nuxt、Vue。空白行会移除;页面的减少行数包含重复行与空白行。修改输入后需重新执行。
/* 定义表单 */
const state = reactive({
input: '',
output: '',
})
// 确保在计算行数前,文本不是undefined或空字符串
function getLineCount(text: string) {
return text ? text.split('\n').length : 0
}
// 计算原始行数
const originalLineCount = computed(() => getLineCount(state.input))
// 计算去重后的行数
const deduplicatedLineCount = computed(() => getLineCount(state.output))
// 计算减少的行数
const reducedLineCount = computed(() => originalLineCount.value - deduplicatedLineCount.value)
function deduplicateLines() {
const lines = state.input ? state.input.split('\n') : []
const filteredLines = lines.filter(line => line.trim().length > 0)
const uniqueLines = Array.from(new Set(filteredLines))
state.output = uniqueLines.join('\n')
}