From 65243261259061a3a0f8ec6ab9459fb0325110d6 Mon Sep 17 00:00:00 2001 From: 404 Date: Tue, 27 Jan 2015 10:05:11 +0800 Subject: [PATCH] Chap12.js: function setData() is wrong. > As you can see from the preceding output, this formula succeeds in generating a set of random numbers between 1 and 10 ````js Math.floor(Math.random() * (this.numElements+1)) ```` This will yield 0 if Math.random returns 0. --- Chapter12/Chap12-1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter12/Chap12-1.js b/Chapter12/Chap12-1.js index 2413207..1fdad10 100644 --- a/Chapter12/Chap12-1.js +++ b/Chapter12/Chap12-1.js @@ -16,7 +16,7 @@ function CArray(numElements) { function setData() { for (var i = 0; i < this.numElements; ++i) { this.dataStore[i] = Math.floor(Math.random() * - (this.numElements+1)); + this.numElements) + 1; } }