Skip to main content
saved 15 bytes, updated the test, fixed a bug
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650

##JavaScript (ES6), 105 110 101 9797 82 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n)n=>n.slicepadStart(-99)))(a)>F(b))

###Test

let f =

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n)n=>n.slicepadStart(-99)))(a)>F(b))

console.log(f([
  'Abcd.txt',
  'Cat05.jpg',
  'Meme00.jpeg',
  'abc.txt',
  'cat.png',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 101 97 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)))(a)>F(b))

###Test

let f =

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)))(a)>F(b))

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 101 97 82 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>n.padStart(99)))(a)>F(b))

###Test

let f =

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>n.padStart(99)))(a)>F(b))

console.log(f([
  'Abcd.txt',
  'Cat05.jpg',
  'Meme00.jpeg',
  'abc.txt',
  'cat.png',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

saved 4 bytes
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650

##JavaScript (ES6), 105 110 101101 97 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.mapsort(s=>[s(a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort(a).map>F(a=>a[1]b))

###Test

let f =

a=>a.mapsort(s=>[s(a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort(a).map>F(a=>a[1]b))

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 101 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.map(s=>[s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort().map(a=>a[1])

###Test

let f =

a=>a.map(s=>[s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort().map(a=>a[1])

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 101 97 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)))(a)>F(b))

###Test

let f =

a=>a.sort((a,b)=>(F=s=>s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)))(a)>F(b))

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

saved 9 bytes
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650

##JavaScript (ES6), 105 110110 101 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.map(s=>[s.toLowerCase().replace(/\d+|\D+\d+/g,s=>+s?n=>('0'.repeat(99)+s+n).slice(-99):s.toLowerCase()),s]).sort().map(a=>a[1])

###Test

let f =

a=>a.map(s=>[s.toLowerCase().replace(/\d+|\D+\d+/g,s=>+s?n=>('0'.repeat(99)+s+n).slice(-99):s.toLowerCase()),s]).sort().map(a=>a[1])

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.map(s=>[s.replace(/\d+|\D+/g,s=>+s?('0'.repeat(99)+s).slice(-99):s.toLowerCase()),s]).sort().map(a=>a[1])

###Test

let f =

a=>a.map(s=>[s.replace(/\d+|\D+/g,s=>+s?('0'.repeat(99)+s).slice(-99):s.toLowerCase()),s]).sort().map(a=>a[1])

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

##JavaScript (ES6), 105 110 101 bytes

Assumes that each numeric element is up to 99 characters long.

a=>a.map(s=>[s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort().map(a=>a[1])

###Test

let f =

a=>a.map(s=>[s.toLowerCase().replace(/\d+/g,n=>('0'.repeat(99)+n).slice(-99)),s]).sort().map(a=>a[1])

console.log(f([
  'Cat05.jpg',
  'Meme00.jpeg',
  'cat1.jpeg',
  'cat02.jpg',
  'meme03-1.jpeg',
  'meme03-02.jpg',
  'meme04.jpg'
]).join('\n'))

deleted 20 characters in body
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650
Loading
fixed version
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650
Loading
added 10 characters in body
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650
Loading
added a note about the length of each element
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 650
Loading