Skip to content
Open
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
26 changes: 26 additions & 0 deletions codewars/7kyu/number-like-counter/koronya.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// [JS][7kyu] Number-like counter
// number-like-counter
// https://www.codewars.com/kata/5313b713bb244a0eb20001fe/train/javascript

class Counter {
constructor() {
this.value = 0
}

incr() {
this.value += 1
return this
}

[Symbol.toPrimitive](hint) {
return this.value
}
}

const c = new Counter()
c.incr()
c + 1 // 2
c > 1 // false
c > 0 // true
c == 1 // true
Math.sqrt(c) // 1