Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clive-cudi - Clive #403

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
/assets
/archive

# production
/build

# misc
.DS_Store
*.pem
tasks_todo.md
todo.md

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
23 changes: 23 additions & 0 deletions clive-cudi/count_zeros.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { CountZeros: countZeros} = require("./count_zeros");

describe('countZeros', () => {
test('returns 0 when given an empty array', () => {
expect(countZeros([])).toBe(0);
});

test('returns 0 when given an array with no zeros', () => {
expect(countZeros([1, 2, 3])).toBe(0);
});

test('returns 1 when given an array with a single zero', () => {
expect(countZeros([0])).toBe(1);
});

test('returns the correct count when given an array with multiple zeros', () => {
expect(countZeros([1, 0, 5, 6, 0, 2])).toBe(2);
});

test('returns the correct count when given an array with all zeros', () => {
expect(countZeros([0, 0, 0, 0, 0])).toBe(5);
});
});
18 changes: 18 additions & 0 deletions clive-cudi/count_zeros.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Write a function CountZeros(A) that takes in an array of integers A, and returns the number of 0's in that array.
* For example, given [1, 0, 5, 6, 0, 2], the function/method should return 2.
*/

function CountZeros(A: number[]): number {
let count = 0;

for (let i = 0; i < A.length; i++) {
if (A[i] === 0) {
count++;
}
}

return count;
}

module.exports = {CountZeros};
5 changes: 5 additions & 0 deletions clive-cudi/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
Loading