Measurement of quark- and gluon-like jet fractions using jet charge in PbPb and pp collisions at 5.02 TeV