Add two challenge solutions that were pretty hard for me

This commit is contained in:
CherryKitten 2022-10-13 19:21:52 +02:00
parent 403c915320
commit ffd2b35c17
Signed by: sammy
GPG key ID: 0B696A86A853E955
2 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,41 @@
const Person = function(firstAndLast) {
// Only change code below this line
// Complete the method below and implement the others similarly
const props = {
_firstName: firstAndLast.split(" ").splice(0, 1).join(),
_lastName: firstAndLast.replace(/(\w+\s)(\w+$)/, "$2"),
_fullName: firstAndLast,
};
const getFullName = () => props._fullName;
const getFirstName = () => props._firstName;
const getLastName = () => props._lastName;
const setFullName = (full) => props._fullName = full;
const setFirstName = (first) => props._firstName = first;
const setLastName = (last) => props._lastName = last;
this.getFullName = function() {
return getFullName();
};
this.getFirstName = function() {
return getFirstName();
}
this.getLastName = function() {
return getLastName();
}
this.setFullName = function(firstAndLast) {
setFullName(firstAndLast);
setFirstName(firstAndLast.split(" ").splice(0, 1).join());
setLastName(firstAndLast.replace(/(\w+\s)(\w+$)/, "$2"));
};
this.setFirstName = function(first){
setFirstName((first));
setFullName(first + " " + getLastName())
};
this.setLastName = function(last){
setLastName(last);
setFullName(getFirstName() + " " + last)
}
};
const bob = new Person('Bob Ross');

View file

@ -0,0 +1,15 @@
function orbitalPeriod(arr) {
const GM = 398600.4418;
const earthRadius = 6367.4447;
let orbitalPeriod = 0;
const response = [];
for (let elem in arr){
let avgAlt = arr[elem]['avgAlt'];
let name = arr[elem]['name'];
response.push({name: name, orbitalPeriod: orbitalPeriod})
}
return response;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);