@@ -257,24 +257,36 @@ const byteToHex = [
257257 'ff'
258258]
259259
260- const fastArrayJoin = ( array , separator = '' ) => {
260+ const fastArrayJoin = ( array , separator = ', ' ) => {
261261 const length = array . length
262- let result = ''
263262 const last = length - 1
264- for ( let i = 0 ; i < length ; i ++ ) {
265- if ( array [ i ] === null || array [ i ] === undefined ) {
266- if ( i !== last ) result += separator
267- } else if ( typeof array [ i ] === 'object' || typeof array [ i ] === 'function' ) {
263+ let result = ''
264+ const stringifyValue = ( anyValue ) => {
265+ const type = typeof anyValue
266+ if ( type === 'string' ) {
267+ return anyValue
268+ } else if ( type === 'number' ) {
269+ return anyValue . toString ( )
270+ } else if ( type === 'object' || type === 'function' ) {
268271 let value = '[object Object]'
269- if ( typeof array [ i ] . toString === 'function' ) {
270- const toStringValue = array [ i ] . toString ( )
272+ if ( typeof anyValue . toString === 'function' ) {
273+ const toStringValue = anyValue . toString ( )
271274 if ( typeof toStringValue === 'string' ) value = toStringValue
272275 }
273- result += i !== last ? value + separator : value
274- } else {
275- result += i !== last ? array [ i ] + separator : array [ i ]
276+ return value
277+ }
278+ }
279+
280+ for ( let i = 0 ; i < length ; i ++ ) {
281+ const isLast = i === last
282+ if ( array [ i ] === null || array [ i ] === undefined ) {
283+ if ( ! isLast ) result += separator
284+ continue
276285 }
286+ const value = stringifyValue ( array [ i ] )
287+ result += ! isLast ? value + separator : value
277288 }
289+
278290 return result
279291}
280292
0 commit comments