JSFiddle - React, Tailwind, and code Playground

by Marco Abate

JavaScript

function getCombinations(items) {
	let result = []

	const pow = (x, n, m = []) => {
		if (n > 0) {
			for (var index = 0; index < items.length; index++) {
				if (items[index] && m.indexOf(items[index]) === -1) {
					const value = pow(x, items.length - 1, [...m, items[index]])
					result.push(value)
				}

			}
		}
		return m
	}
	pow(items.length, items.length)

	return result.sort((a, b) => b.length - a.length)
}

const combinationsSuffixes = ['android','pq','staging','it','ts']

const combinations = getCombinations(combinationsSuffixes)

console.log(combinations)