I have a ruby array of filepaths (./dir2/chico.html) and I can't seem to get it to sort correctly -
so have array: (this isn't exact order of elements, example)
myarray = {./dir2/chico.html, ./dir2/chico.rb, ./dir1/c.js, ./dir1/g.txt, ./dir1/d.css} when sort using...
myarray.sort the results come out unsorted...
./dir2/chico.html ./dir2/chico.rb ./dir1/c.js ./dir1/g.txt ./dir1/d.css what want dir1 files come before dir2. , d.css should come before g.txt. why isn't sorting?
building off "user2891803" said. need construct array differently. have initialized hash name of "myarray" giving false sense of type of container using. when coding, goes languages, try name variables descriptive, concise, , precise possible; don't afraid make long variable names. underscores work wonders in readability!
myarray = ['./dir2/chico.html', './dir2/chico.rb', './dir1/c.js', './dir1/g.txt', './dir1/d.css'] puts myarray.sort this should work trying do. happy ruby!
Comments
Post a Comment