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
28 changes: 20 additions & 8 deletions __tests__/pieceOfCake/array_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('for array', () => {

// <--start
// Please write down the correct result. You should write the result directly.
const expected = undefined;
const expected = 3;
// --end->

expect(array[2]).toEqual(expected);
Expand All @@ -15,7 +15,9 @@ describe('for array', () => {

// <--start
// Please write one line of code to push some elements in the array to pass the test

// const newArray=[6,7,8];
// array.push(...newArray);
array.push(6, 7, 8);
// --end->

expect(array).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
Expand All @@ -27,7 +29,7 @@ describe('for array', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [9,1,2,3,4,5,10];
// --end->

expect(newArray).toEqual(expected);
Expand All @@ -38,8 +40,8 @@ describe('for array', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expectedRow = undefined;
const expectedColumn = undefined;
const expectedRow = 2;
const expectedColumn = 3;
// --end->

expect(row).toEqual(expectedRow);
Expand All @@ -52,7 +54,7 @@ describe('for array', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [2,4];
// --end->

expect(filtered).toEqual(expected);
Expand All @@ -64,7 +66,13 @@ describe('for array', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [
'Unit 1 for element at index 0',
'Unit 2 for element at index 1',
'Unit 3 for element at index 2',
'Unit 4 for element at index 3',
'Unit 5 for element at index 4',
];
// --end->

expect(mapped).toEqual(expected);
Expand All @@ -74,9 +82,13 @@ describe('for array', () => {
const numbers = [1, 2, 3, 4, 5];
const reduced = numbers.reduce((prev, current) => prev + current);

// const initialValue=100;
// const reducedWithInitialValue = numbers.reduce((prev, current) => prev + current,initialValue);
// console.log(reducedWithInitialValue);

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 15;
// --end->

expect(reduced).toEqual(expected);
Expand Down
34 changes: 30 additions & 4 deletions __tests__/pieceOfCake/boolean_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
describe('for boolean type', () => {
it('should convert to same type then compare for equality operator', () => {
//https://github.com/mqyqingfeng/Blog/issues/41

const objectLeft = { key: 'value' };
const objectRight = { key: 'value' };

const actual = [
// eslint-disable-next-line no-self-compare, eqeqeq, yoda
1 == 1, '1' == 1, 1 == '1', 0 == false, 0 == null, objectLeft == objectRight, 0 == undefined, null == undefined,
1 == 1,
'1' == 1,
1 == '1',
0 == false,
0 == null,
objectLeft == objectRight,
0 == undefined,
null == undefined, //???
];

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [
true,
true,
true,
true,
false,
false,
false,
true,
];
// --end->

expect(actual).toEqual(expected);
Expand All @@ -22,12 +40,20 @@ describe('for boolean type', () => {

const actual = [
// eslint-disable-next-line no-self-compare, eqeqeq, yoda
3 === 3, 3 === '3', objectLeft === objectRight, null === undefined,
3 === 3,
3 === '3',
objectLeft === objectRight,
null === undefined,
];

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [
true,
false,
false,
false
];
// --end->

expect(actual).toEqual(expected);
Expand Down
43 changes: 22 additions & 21 deletions __tests__/pieceOfCake/function_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 'Hello World';
// --end->

expect(outerFunction()).toEqual(expected);
Expand All @@ -26,7 +26,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 'Hello World';
// --end->

expect(greeting(sayHello, 'World')).toEqual(expected);
Expand All @@ -37,7 +37,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 36;
// --end->

expect(square(6, 'Hello', 4)).toEqual(expected);
Expand All @@ -51,8 +51,8 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expectedForSingleArgument = undefined;
const expectedForTwoArguments = undefined;
const expectedForSingleArgument = -5;
const expectedForTwoArguments = 2;
// --end->

expect(minus(5)).toEqual(expectedForSingleArgument);
Expand All @@ -70,7 +70,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 16;
// --end->

expect(power(4)).toEqual(expected);
Expand All @@ -89,8 +89,8 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expectedReturnValue = undefined;
const expectedWord = undefined;
const expectedReturnValue = 'Changed';
const expectedWord = 'Origin';
// --end->

expect(returnValue).toEqual(expectedReturnValue);
Expand All @@ -110,10 +110,12 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expectedName = undefined;
const expectedReturnValueName = undefined;
const expectedName = 'Bob';
const expectedReturnValueName = 'Bob';
// --end->

// console.log(returnValue===person);

expect(person.name).toEqual(expectedName);
expect(returnValue.name).toEqual(expectedReturnValueName);
});
Expand All @@ -128,7 +130,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 'Hello';
// --end->

expect(actual).toEqual(expected);
Expand All @@ -145,7 +147,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 'Changed';
// --end->

expect(guessIfIAmChanged).toEqual(expected);
Expand All @@ -163,10 +165,9 @@ describe('for function', () => {

return find(1, '1');
}

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = '(((1 * 3) + 5) * 3)';
// --end->

expect(findSolution(24)).toEqual(expected);
Expand All @@ -183,7 +184,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 6;
// --end->

expect(sum(1, 2, 3)).toEqual(expected);
Expand All @@ -200,7 +201,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 6;
// --end->

const parameters = [1, 2, 3];
Expand All @@ -223,7 +224,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 25;
// --end->

expect(actual).toEqual(expected);
Expand All @@ -238,7 +239,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [0,3,6];
// --end->

expect(labels).toEqual(expected);
Expand All @@ -253,7 +254,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = false;
// --end->

expect(greaterThan10(3)).toEqual(expected);
Expand All @@ -269,7 +270,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 11;
// --end->

expect(actual).toEqual(expected);
Expand All @@ -289,7 +290,7 @@ describe('for function', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = [0,2,4];
// --end->

expect(logs).toEqual(expected);
Expand Down
5 changes: 3 additions & 2 deletions __tests__/pieceOfCake/numbers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ describe('for numbers', () => {

// <--start
// Please write down the correct value. You should write the final result directly.
const expected = undefined;
const expected = 0.75;
//1?
// --end->

expect(dividingResult).toEqual(expected);
Expand All @@ -15,7 +16,7 @@ describe('for numbers', () => {

// <--start
// Please write an expression determine if `notNumber` is NaN.
const isNan = undefined;
const isNan = isNaN(notNumber);
// --end->

expect(isNan).toBeTruthy();
Expand Down
Loading