@@ -36,7 +36,8 @@ function Tuple(tuple) {
36
36
} else if ( typeof tuple [ i ] === "boolean" || typeof tuple [ i ] === "number" || typeof tuple [ i ] === "string" ) {
37
37
this . tup [ i ] = { 'val' : tuple [ i ] } ;
38
38
} else if ( Array . isArray ( tuple [ i ] ) ) {
39
- this . tup [ i ] = ( new Tuple ( tuple [ i ] ) ) . _tupleToObject ( ) ;
39
+ // this.tup[i] = (new Tuple(tuple[i]))._tupleToObject();
40
+ this . tup [ i ] = new Tuple ( tuple [ i ] ) ;
40
41
} else {
41
42
//return error if the input is incorrect
42
43
return null ;
@@ -50,79 +51,80 @@ function Tuple(tuple) {
50
51
51
52
} ;
52
53
53
- Tuple . prototype . _tupleToObject = function ( ) {
54
- if ( this instanceof Tuple ) {
55
- return this . tup ;
56
- }
57
- return false ;
58
- } ;
54
+ Tuple . prototype . _tupleToObject = function ( ) {
55
+ if ( this instanceof Tuple ) {
56
+ return this . tup ;
57
+ }
58
+ return false ;
59
+ } ;
59
60
60
- Tuple . prototype . findValue = function ( keyOrIndex ) {
61
- var x = this . tup [ keyOrIndex ] ;
62
- if ( x instanceof Object ) {
63
- return x ;
64
- } else {
65
- return x === undefined ? undefined : this . tup [ keyOrIndex ] [ "val" ] ;
66
- }
67
- } ;
61
+ Tuple . prototype . findValue = function ( keyOrIndex ) {
62
+ var x = this . tup [ keyOrIndex ] ;
63
+ // console.log(x["tup"]);
64
+ if ( x instanceof Tuple ) {
65
+ return x [ "tup" ] ;
66
+ } else {
67
+ return x === undefined ? undefined : this . tup [ keyOrIndex ] [ "val" ] ;
68
+ }
69
+ } ;
68
70
69
- Tuple . prototype . modifyVal = function ( keyOrIndex , newVal ) {
70
- var x = this . tup [ keyOrIndex ] ;
71
- if ( x === undefined ) {
72
- return false ;
73
- }
74
-
75
- if ( typeof x [ 'val' ] === typeof newVal ) {
76
- x [ 'val' ] = newVal ;
77
- if ( x . hasOwnProperty ( 'key' ) ) {
78
- var otherKey = x [ 'key' ] ;
79
- this . tup [ otherKey ] [ 'val' ] = newVal ;
80
- }
81
- return true ;
82
- }
71
+ Tuple . prototype . modifyVal = function ( keyOrIndex , newVal ) {
72
+ var x = this . tup [ keyOrIndex ] ;
73
+ if ( x === undefined ) {
83
74
return false ;
84
-
85
- } ;
86
-
87
- // Tuple.prototype.deleteElement = function(keyOrIndex) {
88
- // var x = this.tup[keyOrIndex];
89
- // if (x === undefined) {
90
- // return false;
91
- // }
92
- // if (x.hasOwnProperty('key')) {
93
- // var otherKey = x['key'];
94
- // delete this.tup[otherKey];
95
- // }
96
- // delete this.tup[keyOrIndex];
97
- // return true;
98
- // };
75
+ }
76
+
77
+ if ( typeof x [ 'val' ] === typeof newVal ) {
78
+ x [ 'val' ] = newVal ;
79
+ if ( x . hasOwnProperty ( 'key' ) ) {
80
+ var otherKey = x [ 'key' ] ;
81
+ this . tup [ otherKey ] [ 'val' ] = newVal ;
82
+ }
83
+ return true ;
84
+ }
85
+ return false ;
86
+
87
+ } ;
99
88
89
+ // Tuple.prototype.deleteElement = function(keyOrIndex) {
90
+ // var x = this.tup[keyOrIndex];
91
+ // if (x === undefined) {
92
+ // return false;
93
+ // }
94
+ // if (x.hasOwnProperty('key')) {
95
+ // var otherKey = x['key'];
96
+ // delete this.tup[otherKey];
97
+ // }
98
+ // delete this.tup[keyOrIndex];
99
+ // return true;
100
+ // };
100
101
101
- // Tuple.prototype.moveElement = function(oldKeyorIndex, newIndex) {
102
-
103
- // };
104
102
105
- Tuple . prototype . renameElement = function ( oldKey , newKey ) {
106
- //partially implimented
107
- if ( ! isNaN ( oldKey ) || ! isNaN ( newKey ) ) {
108
- return false ;
109
- }
110
- var x = this . tup [ oldKey ] ;
111
- if ( x === undefined ) {
112
- return false ;
113
- }
103
+ // Tuple.prototype.moveElement = function(oldKeyorIndex, newIndex) {
104
+
105
+ // };
114
106
115
- if ( oldKey !== newKey && typeof oldKey === "string" && typeof newKey === "string" ) {
116
- var val = x [ 'val' ] ;
117
- var index = x [ 'key' ] ;
118
- this . tup [ index ] [ 'key' ] = newKey ;
119
- this . tup [ newKey ] = x ;
120
- delete this . tup [ oldKey ] ;
121
- return true ;
122
- }
107
+ Tuple . prototype . renameElement = function ( oldKey , newKey ) {
108
+ //partially implimented
109
+ if ( ! isNaN ( oldKey ) || ! isNaN ( newKey ) ) {
123
110
return false ;
124
- } ;
111
+ }
112
+ var x = this . tup [ oldKey ] ;
113
+ if ( x === undefined ) {
114
+ return false ;
115
+ }
116
+
117
+ if ( oldKey !== newKey && typeof oldKey === "string" && typeof newKey === "string" ) {
118
+ var val = x [ 'val' ] ;
119
+ var index = x [ 'key' ] ;
120
+ this . tup [ index ] [ 'key' ] = newKey ;
121
+ this . tup [ newKey ] = x ;
122
+ delete this . tup [ oldKey ] ;
123
+ return true ;
124
+ }
125
+ return false ;
126
+ } ;
125
127
126
- Tuple . prototype . constructor = Tuple ;
128
+ Tuple . prototype . constructor = Tuple ;
127
129
128
130
module . exports = Tuple ;
0 commit comments