Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script language=javascript>
- <!--
- var by = function(name)
- {
- return function(o,p)
- {
- var a,b;
- if(typeof o === 'object' && typeof p === 'object' && o && p)
- {
- a = o[name];
- b = p[name];
- if(a === b)
- {
- return 0;
- }
- if(typeof a === typeof b)
- {
- return a < b ? -1 : 1;
- }
- return typeof a < typeof b ? -1 : 1;
- }else
- {
- throw {
- name: 'Error',
- message: name + 'を含むオブジェクトが必要です。'
- };
- }
- };
- };
- var s = [
- {first: 'Joe',last: 'Besser'},
- {first: 'Moe',last: 'Howard'},
- {first: 'Joe',last: 'DeRita'},
- {first: 'Shemp',last: 'Howard'},
- {first: 'Larry',last: 'Fine'},
- {first: 'Curly',last: 'Howard'}
- ];
- s = s.sort(by('first'));
- for(var i=0;i<s.length;i+=1)
- {
- alert(s[i].first);
- }
- //-->
- </script>
- </head>
- <body>
- </body>
- </html>
Add Comment
Please, Sign In to add comment