Sorting on table function/outside

I need to sort partOfArray table
I need to getText , upperToCase

when do outside function I got “partOfArray is not defined”

when doing te same inside function cannot read properties of undefinied (reading each)

code it('name sorting test', () => { cy.visit(`${Cypress.env('res - Pastebin.com