/
Amo
/
TProgramming_2025
Обзор
Документация
Войти
/
Amo
/
TProgramming_2025
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
codewars/Permutations/permutations.js
26 строк
735 B
adm
Add solutions for 20 CodeWars tasks
21 окт 2025, 15:10
21 окт 2025, 15:10
8ac4f16
Код
Авторство
О чём код?
function permutations(str) { if (str.length <= 1) return [str]; const result = []; const chars = str.split(''); function permute(current, remaining) { if (remaining.length === 0) { result.push(current); return; } const used = new Set(); for (let i = 0; i < remaining.length; i++) { if (used.has(remaining[i])) continue; used.add(remaining[i]); const nextCurrent = current + remaining[i]; const nextRemaining = remaining.slice(0, i) + remaining.slice(i + 1); permute(nextCurrent, nextRemaining); } } permute('', chars.join('')); return result; }