Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions BuildingBlocks/some problem lesson 3.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
//==========================================================
//------------------------Problem09-------------------------
//==========================================================
lesson 5 change on my own Anabelle
Sam Smith
Add something here
/*
Write a function, intersection, that takes two arrays and returns a new array containing
only the values that are in both arrays.
a: check array 1 elements against array 2
i: two or more arrays
o: a union or intersection of shared elements
e: one array might be longer than the other
Write a function, transformAndRepeat that takes a string, a transformer function,
and a number, and returns the result of invoking the transformer function with the string, repeated number times.
See the tests for additional examples.
My personal notes:
i = string, a helper function, and number, n.
o = a string, repeated n times
a =
e = the string may be all caps or mix of upper/lower case, it may contain more than one word.
the first "letter" may not be a letter at all, but a #. does that matter?
the helper function (or functions) must be capable of performing different operations
1. converting all chars to lowercase
2. only repeating 1st char
3. need to append/concatenate char to end of a string
*/
function intersection (array1, array2) {




//intersection(['a', 'b', 'c', 'f', 'g'], ['d', 'b', 'c', 'd', 'e'])); // --> ['b', 'c']
intersection([1, 4, 6, 2], [10, 9, 4, 1, 5, 6]); // --> [1, 4, 6]
console.log(transformAndRepeat('HELLO', lowerCase, 3)); // --> 'hellohellohello'
console.log(transformAndRepeat('doggo', firstLetter, 6)); // --> 'dddddd'
console.log(transformAndRepeat('hi', exclaim, 4)); // --> 'hi! hi! hi! hi!
37 changes: 37 additions & 0 deletions HREXT/Problem 10 strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Write a function, transformAndRepeat that takes a string, a transformer function,
and a number, and returns the result of invoking the transformer function with the
string, repeated number times.

My personal notes:
i = string, a helper function, and number, n.
o = a string, repeated n times
a = the helper function (or functions) need to support performing different operations on given string
e = the string may be all caps or mix of upper/lower case, it may contain more than one word.
the first "letter" may not be a letter at all, but a #. does that matter?

tranformation requirements:
1. convert all chars to lowercase
2. only repeating 1st char
3. append/concatenate char to end of passed-in string, then repeat
*/
function transformAndRepeat (str, transformReq, num) {

/*two actions for potential helper function(s)
1. 3 transform types
observation 1: because each scenario applies repitition in different ways (e.g. to first char, to end of string, to all chars of string),
plan to first apply transformation requirement to string, then apply repetition.
observation 2: should consider writing code such that additional transform types can easily be added later?
efficiency: b/c each transform type is unique, what approach performs more optimally?
approach1: use if ... else. as in, if (str action === lowercase), //do something
approach2: do seperate helper functions for each transform req/scenario
approach-n: ... or some other better approach?
2. repeat num times
a. Initially wondered whether .push or other method allows me to repeat the same action to a given data type/string num times.
b. After researching found array.fill(value,start,end) that I thought I'd try

}
*/
console.log(transformAndRepeat('HELLO', lowerCase, 3)); // --> 'hellohellohello'
console.log(transformAndRepeat('doggo', firstLetter, 6)); // --> 'dddddd'
console.log(transformAndRepeat('hi', exclaim, 4)); // --> 'hi! hi! hi! hi!
88 changes: 88 additions & 0 deletions Immersive_Readiness/Practice Problem from Steve for Interview.js
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);