You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The introduction of this book alluded to the following as a nice way to compute the sum of a range of numbers:
4
+
5
+
console.log(sum(range(1, 10)));
6
+
Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end.
7
+
8
+
Next, write a sum function that takes an array of numbers and returns the sum of these numbers. Run the previous program and see whether it does indeed return 55.
9
+
10
+
As a bonus assignment, modify your range function to take an optional third argument that indicates the “step” value used to build up the array. If no step is given, the array elements go up by increments of one, corresponding to the old behavior. The function call range(1, 10, 2) should return [1, 3, 5, 7, 9]. Make sure it also works with negative step values so that range(5, 2, -1) produces [5, 4, 3, 2].
console.warn("Overriding existing Array.prototype.equals. Possible causes: New API defines the method, there's a framework conflict or you've got double inclusions in your code.");
41
+
// attach the .equals method to Array's prototype to call it on any array
0 commit comments