Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions algos/level1/week3/emin.index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const arr = (count = 0) => {
return new Array(count).fill(0).map((_, index) => index)
}

module.exports = { arr }
25 changes: 25 additions & 0 deletions algos/level1/week3/emin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const arr = require("./emin.index.js").arr

test("arr function exists", () => {
expect(arr).toBeDefined()
})

test("return type is array", () => {
expect(Array.isArray(arr())).toEqual(true)
})

describe("array elements", function () {
test("should get correct answer", function () {
expect(arr(6)).toEqual([0, 1, 2, 3, 4, 5])
expect(arr(1)).toEqual([0])
expect(arr(0)).toEqual([])
})
})

describe("array length", function () {
test("should get correct answer", function () {
expect(arr(6).length).toEqual(6)
expect(arr(1).length).toEqual(1)
expect(arr(0).length).toEqual(0)
})
})
19 changes: 19 additions & 0 deletions algos/level2/week3/emin.index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const get_score = (arr = [4, 2, 2, 3, 3, 4, 2]) => {
score = 0
level = 0
lineCounter = 0
basePoints = [40, 100, 300, 1200]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very good and clean solution in general but it fails when the player doesn't clear any line and we have "0" in our input array. In the instructions, the input range is given from 0 to 4. You seem to have ignored the "0" part also in your tests. ; ) Can you please edit your function and push it again?


for (let line of arr) {
score += basePoints[line - 1] * (level + 1)
lineCounter += line
if (lineCounter >= 10) {
lineCounter -= 10
level++
}
}
return score
}
get_score()

module.exports = { get_score }
15 changes: 15 additions & 0 deletions algos/level2/week3/emin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const get_score = require("./emin.index.js").get_score

test("get_score function exists", () => {
expect(get_score).toBeDefined()
})

test("return type is number", () => {
expect(typeof get_score([])).toEqual("number")
})

describe("scores", function () {
test("should get correct answer", function () {
expect(get_score([4, 2, 2, 3, 3, 4, 2])).toEqual(4900)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be secure with your solution try adding several cases in your tests, especially the tricky ones. ; )

})