Title: javascript2/week3 by Nebiyoutibebu · Pull Request #374 · HackYourFuture/JavaScript2 · GitHub
Open Graph Title: javascript2/week3 by Nebiyoutibebu · Pull Request #374 · HackYourFuture/JavaScript2
X Title: javascript2/week3 by Nebiyoutibebu · Pull Request #374 · HackYourFuture/JavaScript2
Description: javascript2/week3 //2.1 ======================================= function foo(func) { func () ; } function bar() { console.log('Hello, I am bar!'); } foo(bar); //2.2/ ======================================= function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { const numbers = []; // Replace this comment and the next line with your code //console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); for (let i = startIndex; i <= stopIndex; i++){ numbers.push(i); } console.log(numbers); for (let i = 0; i < numbers; i++ ){ if (numbers[j] % 3 === 0 && numbers[j] % 5 === 0){ threeCallback(numbers[i]); fiveCallback(numbers[i]); } else if (numbers[i] % 3 === 0){ threeCallback(numbers[j]); } else if(numbers[i] % 5 === 0){ fiveCallback(numbers[j]); } } } function sayThree(number) { // Replace this comment and the next line with your code console.log(number + " is divisible by three"); } function sayFive(number) { // Replace this comment and the next line with your code console.log(number + " is divisible by five"); } threeFive(10, 15, sayThree, sayFive); // Do not change or remove anything below this line module.exports = threeFive; //2.3 ============================== // While loop function repeatStringNumTimes(str, num) { let accumulatedStr = ''; while (num > 0) { accumulatedStr += str; num--; } return accumulatedStr; } // for loop repeatStringNumTimes("abc", 3); function repeatStringNumTimes(str, num) { let accumulatedStr = ''; for (i = 0; i < 5; i++) { accumulatedStr += str; num--; } return accumulatedStr; } repeatStringNumTimes("abc", 3); // Do while loop function repeatStringNumTimes(str, num) { let accumulatedStr = ''; do { accumulatedStr += str; num --; } while (num > 0); return accumulatedStr; } console.log( repeatStringNumTimes('abc', 3)); //2.4 ============================== function Dog() { this.name = "George", this.color = "White", this.numLegs = 4; } function Dog() { this.name = "George", this.color = "White", this.numLegs = 4; } let hound = new Dog(); //2.5 ================================== function multiplyAll(arr) { var product = 1; // Only change code below this line for(let i=0; i < arr.length; i++){ for (let j=0; j < arr[i].length; j++){ product = product * arr[i][j]; } } // Only change code above this line return product; } // Modify values below to test your code multiplyAll([[100,200],[300,400],[500,600,700]]); // 2.6================================== /*if it is a 2D Array we check each index. since it is going to contain arrays too we need to check if an index is an array. we should store the resulting indeces into a result array to return. Knowing the given array will only be a 2D array, we search each index for an array, and each index that is an array, search again transfering all data to the return array. */ //2.7 ==================================== // value of x in the first function is 9 because x is called outside the function const x = 9; function f1(val) { val = val + 1; return val; } f1(x); console.log(x); /When a parameter is passed by reference, the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller's variable. if you pass by by reference the change reflects outside./ const y = { x: 9 }; function f2(val) { val.x = val.x + 1; return val; } f2(y); console.log(y); 10 /but if you pass by value it makes a copy and pass it so the change will not be reflected outside. in other words When a parameter is passed by value, the caller and callee have two independent variables with the same value and if the callee modifies the parameter variable, the effect is not visible to the caller./ //3,================================== let addSix = createBase(6); function createBase(num){ return function addSix(added){ return num + added } } addSix(10); // returns 16 // Bonus===================== const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; let unique = [...new Set(letters)]; console.log(unique); // returns ['a', 'b', 'c', 'd', 'e', 'f',]
Open Graph Description: javascript2/week3 //2.1 ======================================= function foo(func) { func () ; } function bar() { console.log('Hello, I am bar!'); } foo(bar); //2.2/ =======================...
X Description: javascript2/week3 //2.1 ======================================= function foo(func) { func () ; } function bar() { console.log('Hello, I am bar!'); } foo(bar); //2.2/ ===============...
Opengraph URL: https://github.com/HackYourFuture/JavaScript2/pull/374
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7b1630f8-fb19-628e-e45f-4a95e4a37ff3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A310:313CEF:69DC9D5:9034671:69736278 |
| html-safe-nonce | 5522498d6f58037d316d3c9c88ee5bbd380ba775652eb986df94b4979686bffe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzEwOjMxM0NFRjo2OURDOUQ1OjkwMzQ2NzE6Njk3MzYyNzgiLCJ2aXNpdG9yX2lkIjoiNjQzNTk2NTY4Njg4NjEzMDI5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49a8e2038632019c6dddbae730e01a4f6e76a3cf02b016a524486e33619075a6 |
| hovercard-subject-tag | pull_request:289258292 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/HackYourFuture/JavaScript2/pull/374/files |
| twitter:image | https://avatars.githubusercontent.com/u/45137309?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/45137309?s=400&v=4 |
| og:image:alt | javascript2/week3 //2.1 ======================================= function foo(func) { func () ; } function bar() { console.log('Hello, I am bar!'); } foo(bar); //2.2/ =======================... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4cf879a11b0a28a85543899a36aaee9ec9ca2fb7bedad86c0da5731193c95f01 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/HackYourFuture/JavaScript2 git https://github.com/HackYourFuture/JavaScript2.git |
| octolytics-dimension-user_id | 20858568 |
| octolytics-dimension-user_login | HackYourFuture |
| octolytics-dimension-repository_id | 124885266 |
| octolytics-dimension-repository_nwo | HackYourFuture/JavaScript2 |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 124885266 |
| octolytics-dimension-repository_network_root_nwo | HackYourFuture/JavaScript2 |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fe8be790582ef7a55477ce1918ac0ed16b106d31 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width