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
3 changes: 3 additions & 0 deletions problems/package-lock.json

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

27 changes: 21 additions & 6 deletions problems/problem1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ var assert = require('assert');

// we need 5 test cases. I provided 1 input
let inputs = [
""
"hello",
'world',
'welcome',
'to',
2,
]

let outputs = [

'h',
'w',
'w',
't',
''
]

// Make this function return the first letter of the string that is passed to it. If the string does not have a first letter, return undefined
function f(str) {

if (typeof str !== 'string' || str === '') {
return ''
} else {
return str[0];
}
}




function runTest(i) {
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
}

runTest(0);
Expand Down
28 changes: 25 additions & 3 deletions problems/problem10.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [

'hello world',
'go',
'away',
'FaT',
'man'
]

let outputs = [

'Hello World',
'Go',
'Away',
'Fat',
'Man'
]

/*
Expand All @@ -17,9 +25,23 @@ f("ALL YOUR BASE ARE BELONG"); // All Your Base Are Belong

*/
function f(str) {

var lower = str.toLowerCase()
console.log(lower)
var words = lower.split(' ')
console.log(words)



for (var i=0; i<words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].slice(1);

}

return words.join(' ')

}


function runTest(i) {
if(i > inputs.length) throw new Error("You do not have enough test cases");
var expected = outputs[i];
Expand Down
41 changes: 34 additions & 7 deletions problems/problem11.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,52 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [

[2, 1, 5],
[5, 2, 3],
[5, 'a', 0],
['x', 7, 6],
[2, 9, 'a'],

]

let outputs = [

8,
10,
5,
13,
11
]

/*
Make this function return the sum of all the numbers in the input array. If any element in the array is not a number, skip it. If the array is empty, return zero.
*/
function f(arr) {

var notNum = []
var num = []
var total = 0;

for (var i = 0; i < arr.length; i++) {
if (typeof arr[i] === 'number') {
num.push(arr[i])
} else {
notNum.push(arr[i]);
}
}
console.log(num);

for (var j = 0; j < num.length; j++) {
total += num[j];
console.log(total);
}
console.log(total);
return total
}

function runTest(i) {
if(i > inputs.length) throw new Error("You do not have enough test cases");
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
if (i > inputs.length) throw new Error("You do not have enough test cases");
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
}

runTest(0);
Expand Down
44 changes: 42 additions & 2 deletions problems/problem14.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [

'Lorem ipsumos dolor sit amet consectetur adipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur adipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur adipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur adipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur adipisicing elit. Magni quisquam',
]

let outputs = [

'Lorem ipsumos dolor sit amet consectetur\nadipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur\nadipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur\nadipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur\nadipisicing elit. Magni quisquam',
'Lorem ipsumos dolor sit amet consectetur\nadipisicing elit. Magni quisquam',

]

/*
Expand All @@ -32,8 +41,39 @@ Lorem ipsumos dolor sit amet consectetur
*/
function f(str) {

let result = [];
let subStr = str;

// result.push(str.slice(0,40));
console.log(result);

while (subStr.length >= 40) {
result.push(subStr.slice(0,40));
subStr = subStr.slice(40);

};

result.push(subStr)

const final = result.map(function (str){
if (str[0] === ' '){
return str.slice(1)
}
return str;
})

// "let final" could be replaced by just .join at the end


return final.join('\n');


}

console.log(f(inputs[0]));


f(inputs[0]);
function runTest(i) {
if(i > inputs.length) throw new Error("You do not have enough test cases");
var expected = outputs[i];
Expand Down
20 changes: 17 additions & 3 deletions problems/problem2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
'hello',
'world',
'send',
'nudes',
'blag6'

]

let outputs = [

'o',
'd',
'd',
's',
undefined
]

// Make this function return the last letter of the string that is passed to it. If the string does not have a last letter, return undefined
// Make this function return the last letter of the string that is passed to it.
// If the string does not have a last letter, return undefined
function f(str) {

if (isNaN(str[str.length-1])) {
console.log(str[str.length-1]);
return str[str.length-1]
}
return undefined;
}

function runTest(i) {
Expand Down
32 changes: 28 additions & 4 deletions problems/problem3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,45 @@ var assert = require('assert');
// we need 7 test cases. I've provided 2.
let inputs = [
[2, 4],
[-3, 3]
[-3, 3],
[4, 9],
[2, 6],
[9, 2],
[1, 3],
[2, '']
]

let outputs = [
6,
0
0,
13,
8,
11,
4,
undefined

]

/*
Make this function return the sum of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined.
Make this function return the sum of the two numbers that are passed to it.
If one of the numbers is not passed, or if anything other than numbers are passed, return undefined.
*/
function f(x, y) {
function f(arr) {

var firstNum = arr[0];
var secondNum = arr[1];

if (typeof (firstNum) !== 'number' || typeof (secondNum) !== 'number'){
return undefined
}else {
return firstNum + secondNum;
};



}


function runTest(i) {
var expected = outputs[i];
var actual = f(inputs[i]);
Expand Down
27 changes: 23 additions & 4 deletions problems/problem4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,50 @@ var assert = require('assert');
// we need 8 test cases. I've provided the first 2
let inputs = [
["hello", 4],
['world', 3],
['cheese', 5],
['sausage', 2],
['mushroom', 6],
['onion', 3],
[9, 2],
["", 2]
]

let outputs = [
"o",
'l',
'e',
'u',
'o',
'o',
undefined,
undefined
]

/*
Make this function return the letter at the specified position in the string. If no such letter exists, it should return undefined.
Make this function return the letter at the specified position in the string.
If no such letter exists, it should return undefined.

For example:
f(["hello", 1]); // e
f(["", 4]); // undefined
f(["abc", 0]); // a

*/
function f(arr) {

function f(arr, num) {

console.log(num)
if (typeof (arr[arr[1]]) !== 'string') {
return undefined;
} else {
return arr[arr[1]];
};
}

function runTest(i) {
var expected = outputs[i];
var input = inputs[i];
var actual = f(input[0], input[1]);
var actual = f(input[[0], input[1]]);
assert.deepEqual(actual, expected);
}

Expand Down