File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33const nFibonacci = ( n ) => {
44 // fibonacci sequence: 1 1 2 3 5 8 13 ...
55 // return the nth number in the sequence
6+ if ( n <= 2 ) return 1 ;
7+ return nFibonacci ( n - 2 ) + nFibonacci ( n - 1 ) ;
68} ;
79
810const nFactorial = ( n ) => {
911 // factorial example: !5 = 5 * 4 * 3 * 2 * 1
1012 // return the factorial of `n`
13+ if ( n === 1 ) {
14+ return 1 ;
15+ }
16+ return n * nFactorial ( n - 1 ) ;
1117} ;
1218
1319/* Extra Credit */
1420const checkMatchingLeaves = ( obj ) => {
1521 // return true if every property on `obj` is the same
1622 // otherwise return false
23+ const leaves = [ ] ;
24+ const findLeaves = ( object ) => {
25+ Object . values ( object ) . forEach ( ( value ) => {
26+ if ( value === Object ( value ) ) {
27+ findLeaves ( value ) ;
28+ } else {
29+ leaves . push ( value ) ;
30+ }
31+ } ) ;
32+ } ;
33+ findLeaves ( obj ) ;
34+ return leaves . every ( x => x === leaves [ 0 ] ) ;
1735} ;
1836
1937/* eslint-enable no-unused-vars */
Original file line number Diff line number Diff line change 77class User {
88 constructor ( options ) {
99 // set a username and password property on the user object that is created
10+ this . username = options . username ;
11+ this . password = options . password ;
1012 }
1113 // create a method on the User class called `checkPassword`
1214 // this method should take in a string and compare it to the object's password property
1315 // return `true` if they match, otherwise return `false`
16+ checkPassword ( pwd ) {
17+ return pwd === this . password ;
18+ }
1419}
1520
1621const me = new User ( {
@@ -27,11 +32,12 @@ const checkPassword = function comparePasswords(passwordToCompare) {
2732 // use `this` to access the object's `password` property.
2833 // do not modify this function's parameters
2934 // note that we use the `function` keyword and not `=>`
35+
3036} ;
3137
3238// invoke `checkPassword` on `me` by explicitly setting the `this` context
3339// use .call, .apply, and .bind
34-
40+ me . checkPassword ( ) ;
3541// .call
3642
3743// .apply
You can’t perform that action at this time.
0 commit comments