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

Pass all the linting #453

Merged
merged 4 commits into from
Apr 10, 2021
Merged
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
9 changes: 5 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
},
"env": {
"browser": true,
"browser": false,
"es6": true,
"jest": true,
"node": true
"node": true,
"shelljs": true
},
"extends": [
"eslint:recommended",
Expand All @@ -29,7 +30,7 @@
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
"@typescript-eslint/array-type": "off",
"@typescript-eslint/explicit-function-return-type": [
"warn",
{
Expand Down
25 changes: 13 additions & 12 deletions exercises/practice/crypto-square/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export class Crypto {
constructor(private readonly input: string) {}

get plaintext() {
private get plaintext(): string {
return this.input.toLowerCase().replace(/[^a-zA-Z0-9]/g, '')
}

get ciphertext() {
public get ciphertext(): string {
const chunkSize = this.size
if (chunkSize === 0) {
return ''
Expand All @@ -19,18 +19,18 @@ export class Crypto {
.join(' ')
}

get size(): number {
public get size(): number {
const realLength = Math.sqrt(this.plaintext.length)
return Math.ceil(realLength)
}

ciphertextSegments() {
private ciphertextSegments(): string[] {
const textSegments = this.plaintextSegments()
const columns = []
let i
let j
let currentSegment
let currentLetter
const columns: string[][] = []
let i: number
let j: number
let currentSegment: RegExpMatchArray[number]
let currentLetter: RegExpMatchArray[number][number]

for (i = 0; i < this.size; i += 1) {
columns.push([])
Expand All @@ -45,14 +45,15 @@ export class Crypto {
}
}

const result: string[] = []
for (i = 0; i < columns.length; i += 1) {
columns[i] = columns[i].join('')
result[i] = columns[i].join('')
}

return columns
return result
}

plaintextSegments() {
private plaintextSegments(): RegExpMatchArray {
const plainText = this.plaintext
const chunkSize = this.size

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/diffie-hellman/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const PRIMES = [
7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699,
7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829,
7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919,
];
]

export class DiffieHellman {
constructor(private readonly p: number, private readonly g: number) {
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/grade-school/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ type Grade = number
type StudentRooster = Record<string, Student[]>
type StudentGrades = Map<Student, Grade>
export class GradeSchool {
students: StudentGrades
private students: StudentGrades

constructor() {
this.students = new Map()
}

add(student: Student, level: Grade) {
public add(student: Student, level: Grade): void {
this.students.set(student, level)
}

grade(level: Grade) {
public grade(level: Grade): Student[] {
return Array.from(this.students.entries())
.filter(([, studentGrade]) => studentGrade === level)
.map(([student]) => student)
.sort()
}

roster(): StudentRooster {
public roster(): StudentRooster {
const result: StudentRooster = {}

Array.from(this.students.entries()).forEach(([, studentGrade]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const largestProduct = (digits: string, seriesLength: number) => {
export function largestProduct(digits: string, seriesLength: number): number {
if (seriesLength === 0) {
return 1
}
Expand Down
10 changes: 10 additions & 0 deletions exercises/practice/list-ops/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Instructions append

Using core language features to build and deconstruct arrays via destructuring, and using the array literal `[]` are allowed, but no functions from the `Array.prototype` should be used.

In order to be able to test your solution, ensure `forEach` is implemented.

```typescript
const list = List.create(1, 2)
list.forEach((item) => console.log(item))
// =>
// 1
// 2
```
122 changes: 74 additions & 48 deletions exercises/practice/list-ops/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ const Null: Cons = {
get next() {
return this
},
get values() {
return []
},

get() {
return this.value
},

push(item): Cons {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new Cons(item, this)
},
length() {
Expand All @@ -25,16 +23,22 @@ const Null: Cons = {
concat(): Cons {
return this
},
forEach() {
forEach(): void {
/* done */
},
foldl(_, initial): any {
return initial
foldl<TValue = unknown, TReturn = unknown>(
_: (initial: TReturn, value: TValue) => TReturn,
initial?: TReturn
): TReturn {
return initial as TReturn
},
foldr(_, initial) {
return initial
foldr<TValue = unknown, TReturn = unknown>(
_: (initial: TReturn, value: TValue) => TReturn,
initial?: TReturn
): TReturn {
return initial as TReturn
},
filter() {
filter(): Cons {
return Null
},
reverse(): Cons {
Expand All @@ -44,79 +48,101 @@ const Null: Cons = {
return this
},
}

class Cons {
static fromArray([head, ...tail]: any[]) {
if (head === undefined) {
return Null
}

return new Cons(head, Cons.fromArray(tail || []))
}

constructor(public readonly value: any, public next: Cons = Null) {}

get values() {
return [this.value, ...this.next.values]
}
constructor(public readonly value: unknown, public next: Cons = Null) {}

get(i: number) {
public get(i: number): unknown {
return i === 0 ? this.value : this.next.get(i - 1)
}

push(item: any): this {
public push(item: unknown): this {
this.next = this.next.push(item)
return this
}

length(): number {
public length(): number {
return 1 + this.next.length()
}

append(other: Cons): Cons {
public append(other: Cons): Cons {
return other.foldl((result, item) => result.push(item), this)
}

concat(others: Cons): Cons {
return others.foldl((result, other) => result.append(other), this)
public concat(others: Cons): Cons {
return others.foldl<Cons, Cons>(
(result, other) => result.append(other),
this
)
}

foldl(
callback: (initial: any, value: any) => any,
initial: any = undefined
): any {
return this.next.foldl(callback, callback(initial, this.value))
public foldl<TValue = unknown>(
callback: (initial: TValue, value: TValue) => TValue
): TValue
public foldl<TValue = unknown, TReturn = unknown>(
callback: (initial: TReturn, value: TValue) => TReturn,
initial: TReturn
): TReturn

public foldl<TValue = unknown, TReturn = unknown>(
callback: (initial: TReturn | undefined, value: TValue) => TReturn,
initial?: TReturn
): TReturn {
return this.next.foldl<TValue, TReturn>(
callback,
callback(initial, this.value as TValue)
)
}

forEach(callback: (value: any) => void): void {
public forEach(callback: (value: unknown) => void): void {
this.foldl((_, item) => callback(item))
}

foldr(
callback: (initial: any, value: any) => any,
initial: any = undefined
): any {
return callback(this.next.foldr(callback, initial), this.value)
public foldr<TValue = unknown>(
callback: (initial: TValue, value: TValue) => TValue
): TValue
public foldr<TValue = unknown, TReturn = unknown>(
callback: (initial: TReturn, value: TValue) => TReturn,
initial: TReturn
): TReturn

public foldr<TValue = unknown, TReturn = unknown>(
callback: (initial: TReturn, value: TValue) => TReturn,
initial?: TReturn
): TReturn {
return callback(
this.next.foldr<TValue, TReturn>(callback, initial as TReturn),
this.value as TValue
)
}

filter(predicate: (value: any) => boolean): Cons {
return this.foldl(
public filter<TValue = unknown>(predicate: (value: TValue) => boolean): Cons {
return this.foldl<TValue, Cons>(
(result, item) => (predicate(item) && result.push(item)) || result,
Null
)
}

map(expression: (value: any) => any): Cons {
return this.foldl((result, item) => result.push(expression(item)), Null)
public map<TValue = unknown, TReturn = unknown>(
expression: (value: TValue) => TReturn
): Cons {
return this.foldl<TValue, Cons>(
(result, item) => result.push(expression(item)),
Null
)
}

reverse(): Cons {
public reverse(): Cons {
return this.next.reverse().push(this.value)
}
}

export class List {
constructor(values = []) {
return Cons.fromArray(values)
public static create(...values: unknown[]): Cons {
const [head, ...tail] = values

if (head === undefined) {
return Null
}

return new Cons(head, List.create(...tail))
}
}
Loading