arrays.wjs 754 B

1234567891011121314151617181920212223242526272829303132333435
  1. Array.prototype.toString = function() {
  2. var r = "["
  3. for (var idx = 0; idx < this.length; idx = idx + 1) {
  4. if (idx > 0)
  5. r = r + ", "
  6. r = r + this[idx].toString()
  7. }
  8. return r + "]"
  9. }
  10. Array.prototype.push = function(x) {
  11. this[this.length] = x
  12. this.length = this.length + 1
  13. return x
  14. }
  15. Array.prototype.pop = function() {
  16. var r = this[this.length - 1]
  17. this[this.length - 1] = undefined
  18. this.length = this.length - 1
  19. return r
  20. }
  21. Array.prototype.join = function(delim) {
  22. var r = ""
  23. for (var idx = 0; idx < this.length; idx++) {
  24. if (idx > 0)
  25. r += delim
  26. r += this[idx]
  27. }
  28. return r
  29. }
  30. Array.prototype.concat = function(xs) {
  31. for (var idx = 0; idx < xs.length; idx++)
  32. this.push(xs[idx])
  33. return this
  34. }