-
Notifications
You must be signed in to change notification settings - Fork 39
Functions done #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lillapulay
wants to merge
19
commits into
Integrify-Finland:master
Choose a base branch
from
lillapulay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8128f3d
Add function
lillapulay c37148a
Multiply function
lillapulay 2174c93
OddOrEven function
lillapulay 3e88224
ArrayGenerator function
lillapulay 164ed32
Hoisting function
lillapulay fa11753
MinValue function
lillapulay 11b3f5c
Add function - arrow
lillapulay 271e122
Multiply function - arrow
lillapulay 568cf3f
OddOrEven function - arrow + ternary
lillapulay f305395
Hoisting function - arrow
lillapulay 4466fb1
MinValue function - arrow
lillapulay 4bb2753
ArrayGenerator function - arrow
lillapulay 3be1cf7
Remove unnecessary declaration
lillapulay 40d0a54
DoubleArray function
lillapulay 540cfdc
DoubleArray function - arrow
lillapulay d1cf2df
Fixed input to accept an array
lillapulay 570a93a
FindStudentName function
lillapulay f34c4d9
FindStudentName function - arrow
lillapulay 337f143
Updated to map() function
lillapulay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,87 @@ | ||
| // 1. Add function code goes here | ||
| exports.add = function add() {}; | ||
| exports.add = function add(x, y) { | ||
| return x + y | ||
| }; | ||
|
|
||
| // 2. Multiply function code goes here | ||
| exports.multiply = function multiply() {}; | ||
| exports.multiply = function multiply(x, y) { | ||
| return x * y | ||
| }; | ||
|
|
||
| // 3. OddOrEven function code goes here | ||
| exports.oddOrEven = function oddOrEven() {}; | ||
| exports.oddOrEven = function oddOrEven(x) { | ||
| if(x % 2 == 0) { | ||
| return ('even') | ||
| } else { | ||
| return ('odd') | ||
| } | ||
| }; | ||
|
|
||
| // 4. Write a function that returns an array that includes number 1 to 100 | ||
| // Ex: [1,2,3,4, ..., 99, 100] | ||
| exports.arrayGenerator = function arrayGenerator() {}; | ||
| exports.arrayGenerator = function arrayGenerator() { | ||
| let numbers = []; | ||
| for(i=1; i<=100; i++) { | ||
| numbers.push(i); | ||
| } | ||
| return(numbers); | ||
| }; | ||
|
|
||
| // 5. Fix this function. We want to see 2 in the console instead of undefined | ||
| exports.hoisting = function hoisting() { | ||
| console.log(y); // undefined | ||
| let y = 2; | ||
| return (y); | ||
| }; | ||
|
|
||
| // 6. Write a function that accepts unlimited amount of numbers as input | ||
| // and return the smallest value | ||
| exports.minValue = function minValue() {}; | ||
| exports.minValue = function minValue(...numbers) { | ||
| return Math.min(...numbers); | ||
| }; | ||
|
|
||
| // 7. Write a function that accepts an array of numbers as input | ||
| // and return a new array with all numbers doubled | ||
| // Ex: [1,2,3] => [2,4,6] | ||
| exports.doubleArray = function doubleArray() {}; | ||
| exports.doubleArray = function doubleArray(input) { | ||
| return input.map(x => x * 2); | ||
| }; | ||
|
|
||
| // 8. We have an array of students object, each object will have a name property | ||
| // write a function that accepts a student array as first parameter, and a name as second parameter | ||
| // and return the student with that name | ||
| // Example of student array: const students = [{ name: 'a' }, { name: 'b' }]; | ||
| exports.findStudentName = function findStudentName() {}; | ||
| exports.findStudentName = function findStudentName (studentList, name) { | ||
| return studentList.filter(student => student.name === name); | ||
| }; | ||
|
|
||
| // 9. Transform all of the above into arrow functions below here | ||
|
|
||
| // 1. ADD | ||
| const add = (x, y) => x + y; | ||
|
|
||
| // 2. MULTIPLY | ||
| const multiply = (x, y) => x * y; | ||
|
Comment on lines
+59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may no need for spaces |
||
|
|
||
| // 3. ODDOREVEN | ||
| const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; | ||
|
|
||
| // 4. ARRAYGENERATOR | ||
| const arrayGenerator = () => { | ||
| let numbers = []; | ||
| for(i=1; i<=100; i++) { | ||
| numbers.push(i); | ||
| } | ||
| return(numbers); | ||
| }; | ||
|
|
||
| // 5. HOISTING | ||
| const hoisting = () => y = 2; | ||
|
|
||
| // 6. MINVALUE | ||
| const minValue = (...numbers) => Math.min(...numbers); | ||
|
|
||
| // 7. DOUBLEARRAY | ||
| const doubleArray = (input) => input.map(x => x * 2); | ||
|
|
||
| // 8. FINDSTUDENTNAME | ||
| const findStudentName = (studentList, name) => studentList.filter(student => student.name === name); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work.