-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjOperationClosure.js
More file actions
68 lines (58 loc) · 1.6 KB
/
objOperationClosure.js
File metadata and controls
68 lines (58 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//1st
// function getStringKeysWithoutFilter(obj){
// let stringKeys=[]
// for(let i in obj){
// if (typeof obj[i]==="string"){
// stringKeys.push(i)
// }
// }
// return stringKeys
// }
// const input={name:"john",age:25,city:"New York",occupation:"Engineer",}
// console.log(getStringKeysWithoutFilter(input))
//2nd
// function swapKeysAndValues(obj){
// const swapped={}
// for(let i in obj){
// swapped[obj[i]]=i//swapped.obj.i,,swapped.1=a
// }
// return swapped
// }
// const input={a:1,b:2,c:3}
// console.log(swapKeysAndValues(input))
//3rd
// function createBankAccount(initialBalance){
// let balance=initialBalance
// let newbalance=0
// return{
// deposit: function(amount){
// return `AmountDeposited: ${amount}, NewBalance: ${balance+amount}`
// },
// withdraw: function(amount){
// return `AmountWithdrawed: ${amount}, NewBalance: ${balance-amount}`
// },
// checkBalance: function(){
// return `CurrentBalance: ${balance}`
// }
// }
// }
// const account=createBankAccount(200)
// console.log(account.deposit(50))
// console.log(account.checkBalance())
//4th
// function sumToSingleDigit(num){
// let sum=0;
// let numStr=num.toString();
// let strArr=numStr.split('');
// for (let i=0;i<strArr.length;i++){
// sum+=parseInt(strArr[i]);
// }
// if (sum>9){
// return sumToSingleDigit(sum);
// }
// else{
// return sum;
// }
// }
// let input = sumToSingleDigit(123456)
// console.log(input)