-
Notifications
You must be signed in to change notification settings - Fork 0
added new file omo #6
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
LachelleF
wants to merge
2
commits into
master
Choose a base branch
from
addnewfileomo
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
2 commits
Select commit
Hold shift + click to select a range
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
88 changes: 88 additions & 0 deletions
88
Immersive_Readiness/Practice Problem from Steve for Interview.js
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //1. Write a function 'getBirthday' which takes in an object with year, day, and month properties, and returns a string with the month and day separated by a space. | ||
|
|
||
| var getBirthday = function(obj) { //created function get b-day that takes in an obj | ||
| return obj.month + " " + obj.day; //expression that concatentates obj month and day | ||
| } | ||
|
|
||
| //Sample input: | ||
| var birthdayA = { | ||
| year: 2010, | ||
| day: 19, | ||
| month: "September" | ||
| }; | ||
| var birthdayB = { | ||
| year: 1950, | ||
| day: 20, | ||
| month: "December" | ||
| }; | ||
|
|
||
| getBirthday(birthdayA); //"September 19" // call getBirthday function passing in argument B-day A object | ||
| // getBirthday(birthdayB); //"December 20" | ||
|
|
||
|
|
||
| /*2. Write a function which accepts an array of numbers and a target number. | ||
| This function should return a new array of all numbers from the input array | ||
| which are less than or equal to the input target number.*/ | ||
|
|
||
|
|
||
| var getNumbersLessThan = function(numbersArr, targetNum) { | ||
| var newArray = []; | ||
| for (var i = 0; i < numbersArr.length; i ++) { | ||
| if(numbersArr[i] <= targetNum) { | ||
| newArray.push(numbersArr[i]); | ||
| } | ||
| } | ||
| return newArray; | ||
| } | ||
| var inputArray = [10, 22, 24, 19, 4, 25]; | ||
| //var inputTargetNumA = 25; | ||
| var inputTargetNumB = 10; | ||
|
|
||
| var output = getNumbersLessThan(inputArray, inputTargetNumB); //for A [10, 22, 24, 25] | ||
| //getNumbersLessThan(inputArray, inputTargetNumB); // for B[10, 4] | ||
| console.log(output); | ||
|
|
||
|
|
||
| /*3. You are asked by the head of Human Resources to compile a list of birthdays | ||
| in a given month. Write a function which accepts an array with a structure similar | ||
| to "birthdayCollection", as well as a month. Name this function "birthdaysInMonth"; | ||
| it should return an array of strings with a Month and Day separated by a white space. | ||
|
|
||
| o: a new array with Month and Day for all elements within the birthday Month provided | ||
| i: an array of objects, need to go through each object's elements | ||
| */ | ||
| var birthdayCollection = [ | ||
| { year: 1982, day: 10, month: 'February' }, | ||
| { year: 1966, day: 22, month: 'March' }, | ||
| { year: 2008, day: 19, month: 'December' }, | ||
| { year: 1963, day: 3, month: 'March' }, | ||
| { year: 2000, day: 7, month: 'February' }, | ||
| { year: 1977, day: 18, month: 'February' } | ||
| ]; | ||
|
|
||
| var birthdaysInMonth = function(birthdayObjs, birthdayMonth) { | ||
| var newBirthdayArray = []; | ||
| for (var i = 0; i < birthdayObjs.length; i ++) { | ||
| if (birthdayObjs[i].month === birthdayMonth) { | ||
| newBirthdayArray.push(birthdayObjs[i].month + " " + birthdayCollection[i].day) | ||
| } | ||
| } | ||
| return newBirthdayArray; | ||
| } | ||
| var output = birthdaysInMonth(birthdayCollection, "February"); //[ 'February 10', 'February 7', 'February 18' ] | ||
| console.log(output); | ||
|
|
||
| //4. write a function that takes in two integers and computes the sum between them | ||
| var computeSumBetween = (num1, num2) => { //function that takes in two integrers | ||
| if (num1 > num2) { //addressing exception where num1 is greater than two | ||
| return 0; | ||
| } | ||
| let sum = 0; //est. var sum to store total while looping thru delta btw nums | ||
| for (let i = num1; i < num2; i++) { | ||
| sum += i; | ||
| } | ||
| return sum; | ||
| }; | ||
|
|
||
| var output = computeSumBetween(2,5); //calling function and passing in arguments (two integers) | ||
| console.log(output); | ||
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.
what does this loop do?