Skip to content

Commit 5b96abc

Browse files
author
JorvanW
committed
removed code from sprint 1 and removed prep folder
1 parent 6998347 commit 5b96abc

11 files changed

Lines changed: 35 additions & 64 deletions

File tree

‎Sprint-1/fix/median.js‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,10 @@
55
// Hint: Please consider scenarios when 'list' doesn't have numbers (the function is expected to return null)
66
// or 'list' has mixed values (the function is expected to sort only numbers).
77

8-
function calculateMedian(list) {
9-
list = list.filter(element => typeof element === 'number');
10-
list.sort((a, b) => a - b);
11-
12-
if (list.length % 2 === 0){
13-
const middleIndexR = Math.floor(list.length / 2);
14-
const middleIndexL = middleIndexR - 1
15-
const evenMedian = (list[middleIndexL] + list[middleIndexR]) / 2;
16-
17-
return evenMedian
18-
} else {
19-
const middleIndex = Math.floor(list.length / 2);
20-
const median = list[middleIndex];
21-
return median;
22-
}
23-
8+
function calculateMedian(list) {
9+
const middleIndex = Math.floor(list.length / 2);
10+
const median = list.splice(middleIndex, 1)[0];
11+
return median;
2412
}
2513

26-
27-
2814
module.exports = calculateMedian;

‎Sprint-1/fix/median.test.js‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ describe("calculateMedian", () => {
2727
it(`returns the correct median for unsorted array [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
2828
);
2929

30-
// it("doesn't modify the input array [3, 1, 2]", () => {
31-
// const list = [3, 1, 2];
32-
// calculateMedian(list);
33-
// expect(list).toEqual([3, 1, 2]);
34-
// });
30+
it("doesn't modify the input array [3, 1, 2]", () => {
31+
const list = [3, 1, 2];
32+
calculateMedian(list);
33+
expect(list).toEqual([3, 1, 2]);
34+
});
3535

36-
// [ 'not an array', 123, null, undefined, {}, [], ["apple", null, undefined] ].forEach(val =>
37-
// it(`returns null for non-numeric array (${val})`, () => expect(calculateMedian(val)).toBe(null))
38-
// );
36+
[ 'not an array', 123, null, undefined, {}, [], ["apple", null, undefined] ].forEach(val =>
37+
it(`returns null for non-numeric array (${val})`, () => expect(calculateMedian(val)).toBe(null))
38+
);
3939

40-
// [
41-
// { input: [1, 2, "3", null, undefined, 4], expected: 2 },
42-
// { input: ["apple", 1, 2, 3, "banana", 4], expected: 2.5 },
43-
// { input: [1, "2", 3, "4", 5], expected: 3 },
44-
// { input: [1, "apple", 2, null, 3, undefined, 4], expected: 2.5 },
45-
// { input: [3, "apple", 1, null, 2, undefined, 4], expected: 2.5 },
46-
// { input: ["banana", 5, 3, "apple", 1, 4, 2], expected: 3 },
47-
// ].forEach(({ input, expected }) =>
48-
// it(`filters out non-numeric values and calculates the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
49-
// );
50-
});
40+
[
41+
{ input: [1, 2, "3", null, undefined, 4], expected: 2 },
42+
{ input: ["apple", 1, 2, 3, "banana", 4], expected: 2.5 },
43+
{ input: [1, "2", 3, "4", 5], expected: 3 },
44+
{ input: [1, "apple", 2, null, 3, undefined, 4], expected: 2.5 },
45+
{ input: [3, "apple", 1, null, 2, undefined, 4], expected: 2.5 },
46+
{ input: ["banana", 5, 3, "apple", 1, 4, 2], expected: 3 },
47+
].forEach(({ input, expected }) =>
48+
it(`filters out non-numeric values and calculates the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
49+
);
50+
});

‎Sprint-1/implement/dedupe.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
function dedupe(list) {
2-
return [...new Set(list)];
3-
}
1+
function dedupe() {}

‎Sprint-1/implement/max.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
function findMax(elements) {
2-
elements = elements.filter(element => typeof element === 'number');
3-
if (elements.length === 0){
4-
return -Infinity;
5-
}
6-
return Math.max(...elements);
72
}
3+
84
module.exports = findMax;

‎Sprint-1/implement/sum.js‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
function sum(elements) {
2-
elements = elements.filter(element => typeof element === 'number');
3-
let total = 0;
4-
5-
for (let element of elements) {
6-
total += element;
7-
// += means to add to the current value and assign as result
8-
// elements are individual items inside a collection (not just string)
9-
}
10-
11-
return total;
122
}
133

144
module.exports = sum;

‎Sprint-1/refactor/includes.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Refactor the implementation of includes to use a for...of loop
22

33
function includes(list, target) {
4-
for (const element of list) {
4+
for (let index = 0; index < list.length; index++) {
5+
const element = list[index];
56
if (element === target) {
67
return true;
78
}
89
}
910
return false;
1011
}
1112

12-
1313
module.exports = includes;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "../.."
5+
}
6+
],
7+
"settings": {}
8+
}

‎prep/mean.js‎

Whitespace-only changes.

‎prep/mean.test.js‎

Whitespace-only changes.

‎prep/parse-query-string.js‎

Whitespace-only changes.

0 commit comments

Comments
 (0)