Skip to content

BER Katarzyna Roszak #124

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
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

320 changes: 320 additions & 0 deletions starter-code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 32 additions & 14 deletions starter-code/src/array-functions.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
var ArrayFunctions = function (){}
// var ArrayFunctions = function() {};

// 1) Define a function that takes an array with numbers and prints all the elements of the array, separated by " --- "
// ArrayFunctions.printSpecial([12, 33, 144, 122])
// 12 -- 33 -- 144 -- 122

ArrayFunctions.prototype.printSpecial = function (array) {
return array.join(" --- ");
};
// ArrayFunctions.prototype.printSpecial = function (array) {
// return array.join(" --- ");
// };

class ArrayFunctions {
printSpecial(array) {
return array.join(' --- ');
}

doubleArray(array) {
return array.map(number => {
return number * 2;
});
}

superPower(array) {
return array.reduce((sum, number, index) => {
return sum + number * Math.pow(10, index);
});
}
}

// 2) Define a function that takes an array with numbers and returns another array where each element contains double each element in the array
// ArrayFunctions.doubleMyArray([10, 20, 35, 12])
// [20, 40, 70, 24]

ArrayFunctions.prototype.doubleArray = function(array){
return array.map(function(number){
return number * 2;
});
};
// ArrayFunctions.prototype.doubleArray = function(array) {
// return array.map(function(number) {
// return number * 2;
// });
// };

// 3) Define a function that takes an array with numbers and returns the result of multiplying each element by ten to the power of the position it's in:
// ArrayFunctions.superPower([1,2,3,4,5])
// 54321
// explanation: (1 x 10^0) + (2 x 10^1) + (3 x 10^2) + (4 x 10^3) + (5 x 10^4)
// explanation: (1) + (20) + (300) + (4000) + (50000)

ArrayFunctions.prototype.superPower = function(array){
return array.reduce(function(sum, number, index){
return sum + (number * (Math.pow(10, index)));
});
}
// ArrayFunctions.prototype.superPower = function(array) {
// return array.reduce(function(sum, number, index) {
// return sum + number * Math.pow(10, index);
// });
// };

module.exports = ArrayFunctions;
Loading