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
8 changes: 2 additions & 6 deletions Exercises/1-random.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict';

const random = (min, max) => {
// Generate random Number between from min to max
// Use Math.random() and Math.floor()
// See documentation at MDN
};
// Tests not working (manual testing)
const random = (min, max) => min + Math.floor(Math.random() * (max - min + 1));

module.exports = { random };
13 changes: 8 additions & 5 deletions Exercises/2-key.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

const generateKey = (length, possible) => {
// Generate string of random characters
// Use Math.random() and Math.floor()
// See documentation at MDN
// Tests not working (manual testing)
const generateKey = (length, characters) => {
const randomChar = () => Math.floor(Math.random() * characters.length);
let randChar = '';
for (let char = 1; char <= length; char++) {
randChar += characters[randomChar()];
}
return randChar;
};

module.exports = { generateKey };
10 changes: 4 additions & 6 deletions Exercises/3-ip.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

// Tests not working (manual testing)
const ipToInt = (ip = '127.0.0.1') => {
// Parse ip address as string, for example '10.0.0.1'
// to ['10', '0', '0', '1'] to [10, 0, 0, 1]
// and convert to Number value 167772161 with sitwise shift
// (10 << 8 << 8 << 8) + (0 << 8 << 8) + (0 << 8) + 1 === 167772161
// Use Array.prototype.reduce of for loop
const fn = (res, item) => (res << 8) + parseInt(item);
return ip.split('.').reduce(fn, 0);
};


module.exports = { ipToInt };
22 changes: 6 additions & 16 deletions Exercises/4-methods.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
'use strict';

// Tests not working (manual testing)
const methods = iface => {
// Introspect all properties of iface object and
// extract function names and number of arguments
// For example: {
// m1: x => [x],
// m2: function (x, y) {
// return [x, y];
// },
// m3(x, y, z) {
// return [x, y, z];
// }
// will return: [
// ['m1', 1],
// ['m2', 2],
// ['m3', 3]
// ]
const array = [];
for (const i in iface) {
if (typeof iface[i] === 'function') array.push([i, iface[i].length]);
}
return array;
};

module.exports = { methods };
14 changes: 0 additions & 14 deletions package.json

This file was deleted.