/flash/src/js/utils.js

http://echo-nest-remix.googlecode.com/ · JavaScript · 31 lines · 28 code · 3 blank · 0 comment · 8 complexity · fe355c14c266c154701f0f4c93a355b7 MD5 · raw file

  1. function extend(destination, source) {
  2. for (var property in source) {
  3. destination[property] = source[property];
  4. }
  5. return destination;
  6. }
  7. Array.prototype.sum = function() {
  8. var result = 0;
  9. for (var i = 0; i < this.length; i++) {
  10. result += this[i];
  11. }
  12. };
  13. if (!Array.prototype.indexOf) {
  14. Array.prototype.indexOf = function(elt /*, from*/) {
  15. var len = this.length >>> 0;
  16. var from = Number(arguments[1]) || 0;
  17. from = (from < 0) ? Math.ceil(from) : Math.floor(from);
  18. if (from < 0) {
  19. from += len;
  20. }
  21. for (; from < len; from++) {
  22. if (from in this && this[from] === elt) {
  23. return from;
  24. }
  25. }
  26. return -1;
  27. };
  28. };