diff --git a/2-javascript-algorithms-datastructures/0-somechallenges/bobrossthingy.js b/2-javascript-algorithms-datastructures/0-somechallenges/bobrossthingy.js new file mode 100644 index 0000000..be8a935 --- /dev/null +++ b/2-javascript-algorithms-datastructures/0-somechallenges/bobrossthingy.js @@ -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'); \ No newline at end of file diff --git a/2-javascript-algorithms-datastructures/0-somechallenges/orbitalPeriod.js b/2-javascript-algorithms-datastructures/0-somechallenges/orbitalPeriod.js new file mode 100644 index 0000000..a78ad16 --- /dev/null +++ b/2-javascript-algorithms-datastructures/0-somechallenges/orbitalPeriod.js @@ -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}]); \ No newline at end of file