# Normalized difference of all bands

How I can get the normalized difference of all bands of an image with a function?
to qualify it; I want to gain normalized difference of b(i) with b(j) if j>i and i start from 1.
I want to stack the results.

This is the way I've been doing this:

var image = ee.Image('COPERNICUS/S2/20200101T100319_20200101T100321_T32TQM')
var normalizedDifferences = combinePairwise(image, normalizedDifference, '_nd')

print(normalizedDifferences)
Map.centerObject(image, 10)

function normalizedDifference(img1, img2) {
return img1.expression('(img1 - img2) / (img1 + img2)', {
img1: img1,
img2: img2
})
}

function combinePairwise(image, algorithm, suffix) {
suffix = suffix || ''
return ee.Image(image.bandNames().iterate(function (b1, accImage) {
b1 = ee.String(b1)
accImage = ee.Image(accImage)
var img1 = image.select(b1).rename('img1')
var i1 = image.bandNames().indexOf(b1)
var combinations = ee.Image(image.bandNames().slice(i1.add(1)).iterate(function (b2, accImage) {
b2 = ee.String(b2)
accImage = ee.Image(accImage)
var img2 = image.select(b2).rename('img2')
algorithm(img1, img2)
.rename(b1.cat('_').cat(b2).cat(suffix || ''))
)
}, ee.Image([])))
}, ee.Image([])))
return segment.select('ndfi_.*')
{s: segment}).rename('densityObs')
)
}