Guest User

Untitled

a guest
Feb 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script language=javascript>
  4. <!--
  5. var by = function(name)
  6. {
  7. return function(o,p)
  8. {
  9. var a,b;
  10. if(typeof o === 'object' && typeof p === 'object' && o && p)
  11. {
  12. a = o[name];
  13. b = p[name];
  14. if(a === b)
  15. {
  16. return 0;
  17. }
  18. if(typeof a === typeof b)
  19. {
  20. return a < b ? -1 : 1;
  21. }
  22. return typeof a < typeof b ? -1 : 1;
  23. }else
  24. {
  25. throw {
  26. name: 'Error',
  27. message: name + 'を含むオブジェクトが必要です。'
  28. };
  29. }
  30. };
  31. };
  32. var s = [
  33. {first: 'Joe',last: 'Besser'},
  34. {first: 'Moe',last: 'Howard'},
  35. {first: 'Joe',last: 'DeRita'},
  36. {first: 'Shemp',last: 'Howard'},
  37. {first: 'Larry',last: 'Fine'},
  38. {first: 'Curly',last: 'Howard'}
  39. ];
  40.  
  41. s = s.sort(by('first'));
  42. for(var i=0;i<s.length;i+=1)
  43. {
  44. alert(s[i].first);
  45. }
  46.  
  47. //-->
  48. </script>
  49.  
  50. </head>
  51. <body>
  52. </body>
  53. </html>
Add Comment
Please, Sign In to add comment