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
Binary file added problems/.DS_Store
Binary file not shown.
25 changes: 21 additions & 4 deletions problems/problem1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@ var assert = require('assert');

// we need 5 test cases. I provided 1 input
let inputs = [
""
"",
"hello",
"abc",
"123",
"cat"
]

let outputs = [
undefined,
"h",
"a",
"1",
"c"

]

// 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
// 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"){
return undefined;
}
else {
return str[0];
}
};


function runTest(i) {
var expected = outputs[i];
Expand Down
27 changes: 23 additions & 4 deletions problems/problem10.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
var assert = require('assert');
var assert = require('assert');

// we need 5 test cases.
let inputs = [
"hello WORLD",
"hi there",
'BONJOUR',
"what THE F",
"ok OK OK"

]

let outputs = [
"Hello World",
"Hi There",
"Bonjour",
"What The F",
"Ok Ok Ok"

]

/*
Make this function return the input string, capitalized. You must use a for loop. For example:
Make this function return the input string, capitalized. You must use
a for loop. For example:

f("hello world"); // Hello World
f("ALL YOUR BASE ARE BELONG"); // All Your Base Are Belong

*/
function f(str) {

function f(str){
tempArray= str.toLowerCase().split(' ');
for (let i=0; i <tempArray.length; i ++){
tempArray[i] = tempArray[i].split('');
tempArray[i][0]=tempArray[i][0].toUpperCase();
tempArray[i]= tempArray[i].join('');
}
return tempArray.join(' ');
}



function runTest(i) {
if(i > inputs.length) throw new Error("You do not have enough test cases");
Expand Down
24 changes: 22 additions & 2 deletions problems/problem11.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
[1,1,1],
[],
[1,"cat",1],
[2,3,4],
[true,"cat",1]

]

let outputs = [
3,
0,
2,
9,
1

]

/*
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.
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 sum =0;
for (let i=0; i< arr.length; i ++){
if (typeof arr[i] === "number"){
sum += arr[i];
}
}
return sum;
}



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

// we need 5 test cases.
let inputs = [
[[0,1,2,3],[1,3,4,5]],
[[3,4,22],[22,6,4]],
[[10,10,3],2],
[[2,2,2],[2,2,2]],
[[1,4,3],[1,3,3]]

]
];

let outputs = [
[0,2,4,5],
[3,4,6],
[2,3],
[],
[4]

]
];

/*
Make this function return the elements that are unique to array1 and array2.
Expand All @@ -19,16 +29,44 @@ uniqueElements([0,1,2,3], [1,3,4,5]); // [0,4,5]
uniqueElements([1,2,3], [1,2,3]); // []
uniqueElements(2,3); // undefined, not arrays
*/

/*
member(x,lst) returns true if and only if x is an element of lst
*/

function member (x, lst){
for (let i =0; i< lst.length; i ++ ){
if (lst[i]=== x) {return true}
}
return false
};
function f(arr1, arr2) {
uniArr = [];
for (let i = 0;i<arr1.length; i ++){
if (member(arr1[i],arr2) === false && member(arr1,uniArr)===false)
{
uniArr.push(arr1[i]);
}

}
}return uniArr;
for (let i = 0;i<arr2.length; i ++){
if (member(arr2[i],arr1) === false && member(arr2,uniArr)===false)
{
uniArr.push(arr2[i]);
}
}
return uniArr;

};


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]);
var input = inputs[i];
var actual = f(input[0], input[1]);
assert.deepEqual(actual, expected);
}
};

runTest(0);
runTest(1);
Expand Down
19 changes: 18 additions & 1 deletion problems/problem13.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
"racecAR",
"car",
"ogopogo",
"loop",
"Hanah"

]

let outputs = [
true,
false,
true,
false,
true

]

/*
Make this function return true if the input string is a palindrome, and false otherwise. A palindrome is simply a string that is the same if you reverse it.
Make this function return true if the input string is a palindrome,
and false otherwise. A palindrome is simply a string that is the same
if you reverse it.

RADAR -> Yes
JAVASCRIPT -> No
*/

function f(str) {
var lowStr = str.toLowerCase();
if(lowStr === lowStr.split('').reverse().join('')){
return true
}else {return false};

}

Expand Down
3 changes: 2 additions & 1 deletion problems/problem14.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ let outputs = [

/*
Make this function return the input string wrapped to 40 characters per line.
This means you'll have to insert a newline \n character after every 40 characters in the input string.
This means you'll have to insert a newline \n character after every 40
characters in the input string.
If the next character after a cut is a space, then do not display it.

For example with the input:
Expand Down
18 changes: 17 additions & 1 deletion problems/problem2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
"",
"hello",
"abc",
"123",
"cat"

]

let outputs = [
undefined,
"o",
"c",
"3",
"t"

]

// 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 (typeof str !== "string"){
return undefined
}else {
return str[str.length -1]
}
}

}


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

let outputs = [
6,
0
0,
undefined,
undefined,
20,
4,
2
]

/*
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(x) {
if (typeof x[0] !== "number" || typeof x[1] !== "number"){
return undefined
} else {return x[0]+ x[1]}

}



function runTest(i) {
var expected = outputs[i];
Expand Down
30 changes: 27 additions & 3 deletions problems/problem4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,32 @@ var assert = require('assert');
// we need 8 test cases. I've provided the first 2
let inputs = [
["hello", 4],
["", 2]
["", 2],
[1, 'hello'],
["bonjour", 8],
[4,1],
[["abv"], 4],
["hamburger", 5],
['cat', -1]

]

let outputs = [
"o",
undefined,
undefined,
undefined,
undefined,
undefined,
"r",
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
Expand All @@ -21,9 +37,17 @@ f("abc", 0); // a

*/
function f(str, index) {

if (typeof str !== "string" || typeof index !== "number"){
return undefined
}else if ((index < str.length === false) || (index < 0 === true)){
return undefined
}else {
return str[index];
}
}



function runTest(i) {
var expected = outputs[i];
var input = inputs[i];
Expand Down
Loading