archives

« Bugzilla Issues Index

#922 — 15.5.4.21 String.prototype.repeat should allow a count value of 0


Repeating a string 0 time should yield an empty string.

According to the current version of the spec, it throws a RangeError (at step 6).


For reference, in Ruby:

irb(main):008:0> 'foo' * 3
=> "foofoofoo"
irb(main):009:0> 'foo' * 1
=> "foo"
irb(main):010:0> 'foo' * 0
=> ""
irb(main):011:0> 'foo' * -1
ArgumentError: negative argument
from (irb):11:in `*'
from (irb):11


See also http://rosettacode.org/wiki/Repeat_a_string.

/be


fixed in rev 13 editor's draft