-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
126f7dd
commit a3c2f90
Showing
5 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const init = num => { | ||
return new ChainableArtimatic(num); | ||
}; | ||
|
||
class ChainableArtimatic { | ||
constructor(num) { | ||
this._value = num; | ||
} | ||
|
||
value() { | ||
return this._value; | ||
} | ||
|
||
add(num) { | ||
this._value = this._value + num; | ||
return this; | ||
} | ||
} | ||
|
||
console.log( | ||
init(3) | ||
.add(4) | ||
.add(2) | ||
.value() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// input [1, 3, [4,6], 0, [ [3, 9], 88]] | ||
// output [1, 3, 4, 6, 0, 3, 9, 88] | ||
|
||
const flattenArr = (arr, flatArr = []) => { | ||
arr.forEach(el => { | ||
if (Array.isArray(el)) { | ||
return flattenArr(el, flatArr); | ||
} | ||
flatArr.push(el); | ||
}); | ||
|
||
return flatArr; | ||
}; | ||
|
||
const test1 = [1, 3, [4, 6], 0, [[3, 9], 88]]; | ||
console.log(flattenArr(test1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// O(2N) => O(N) | ||
const isPalindrome = str => { | ||
let isValidPalindrome = true; | ||
let stack = []; | ||
|
||
Array.from(str).forEach(char => { | ||
stack.push(char); | ||
}); | ||
|
||
Array.from(str).forEach(char => { | ||
const poppedChar = stack.pop(); | ||
|
||
if (char !== poppedChar) { | ||
isValidPalindrome = false; | ||
} | ||
}); | ||
|
||
return isValidPalindrome; | ||
}; | ||
|
||
const testStrings = ["abba", "tacocat", "hannah", "cat", "dog"]; | ||
|
||
testStrings.forEach(str => { | ||
console.log(isPalindrome(str)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('[]==0', []===0); |