Skip to content

Commit ed8eace

Browse files
committed
feat: 🎸 added some basic problem solving questions
1 parent 30f0b92 commit ed8eace

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// const functionStore = {
2+
// increase(){
3+
// console.log(this.score++)
4+
// }
5+
// }
6+
7+
// const user = Object.create(functionStore)
8+
// user.score = 0
9+
// console.log(user)
10+
// user.increase()
11+
12+
// 1 1 2 3 5 8 13 21 34 55
13+
14+
const nthFibonacciNumber = n => {
15+
if (n < 2) return n
16+
17+
return nthFibonacciNumber(n - 1) + nthFibonacciNumber(n - 2)
18+
}
19+
20+
// console.log(nthFibonacciNumber(8));
21+
22+
// const mypromise = new Promise((resolve, reject) => {
23+
// setTimeout(() => resolve('promise is resolve'), 1000)
24+
// })
25+
// mypromise.then(data => {
26+
// console.log(data)
27+
// })
28+
29+
const printNthFibonacciNumber = n => {
30+
if (n <= 1) return n
31+
return printNthFibonacciNumber(n - 1) + printNthFibonacciNumber(n - 2)
32+
}
33+
34+
const printToNFibo = n => {
35+
for (let i = 0; i < n; i++) {
36+
console.log(printNthFibonacciNumber(i))
37+
}
38+
}
39+
40+
printToNFibo(10)
41+
const n = printNthFibonacciNumber(1)
42+
console.log('🚀 ~ n:', n)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Write a function to flatten an array
2+
// const nestedArray = [1, 2, [3, 4, [5, 6]], 7, [8, [9]]] => . [1,2,3,4,5,6,7,8,9];
3+
const nestedArray = [1, 2, [3, 4, [5, 6]], 7, [8, [9]]]
4+
5+
const flattenArray = arr => {
6+
let res = []
7+
if (!arr) {
8+
return
9+
}
10+
for (const el of arr) {
11+
if (Array.isArray(el)) {
12+
res = res.concat(flattenArray(el))
13+
} else {
14+
res.push(el)
15+
}
16+
}
17+
return res
18+
}
19+
20+
const res = flattenArray(nestedArray)
21+
console.log('🚀 ~ res:', res)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function printNumbers(n) {
2+
if (n > 1) {
3+
printNumbers(n - 1)
4+
}
5+
console.log(n)
6+
}
7+
8+
const a = printNumbers(5)

0 commit comments

Comments
 (0)