Skip to content

Commit

Permalink
formatting of JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Petrovskiy committed Nov 18, 2023
1 parent a31f820 commit 02a584c
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
* @param {number} target
* @return {number[][]}
*/
var combinationSum = function(candidates, target) {
let result = [
[]
];
candidates.sort();
candidates.reverse();
if (target % candidates[0]) {
let tempResult = [];
for (let i = 0; i < Math.floor(target / candidates[0]); i++) {
tempResult.push(i);
}
result.push(tempResult);
var combinationSum = function (candidates, target) {
let result = [[]];
candidates.sort();
candidates.reverse();
if (target % candidates[0]) {
let tempResult = [];
for (let i = 0; i < Math.floor(target / candidates[0]); i++) {
tempResult.push(i);
}
return result;
result.push(tempResult);
}
return result;
};

module.exports = {
combinationSum
}
combinationSum,
};
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
const { combinationSum } = require("./combination_sum");

describe.each([
[
[2, 3, 6, 7], 8, [
[2, 2, 3],
[7]
]
],
[
[2, 3, 5],
8, [
[2, 2, 2, 2],
[2, 3, 3],
[3, 5],
],
],
[
[2], 1, []
],
[
[1], 1, [
[1]
]
],
[
[1], 2, [
[1, 1]
]
],
])(
"combinationSum(%o, %i) should equal %i",
(candidates, target, expectedResult) => {
test(`candidates = ${candidates}, target = ${target}, returns ${expectedResult}`, () => {
expect(combinationSum(candidates, target)).toEqual(expectedResult);
});
}
);
const { combinationSum } = require("./combination_sum");

describe.each([
[[2, 3, 6, 7], 8, [[2, 2, 3], [7]]],
[
[2, 3, 5],
8,
[
[2, 2, 2, 2],
[2, 3, 3],
[3, 5],
],
],
[[2], 1, []],
[[1], 1, [[1]]],
[[1], 2, [[1, 1]]],
])(
"combinationSum(%o, %i) should equal %i",
(candidates, target, expectedResult) => {
test(`candidates = ${candidates}, target = ${target}, returns ${expectedResult}`, () => {
expect(combinationSum(candidates, target)).toEqual(expectedResult);
});
}
);
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
function combinationSum(candidates: number[], target: number): number[][] {

};
function combinationSum(candidates: number[], target: number): number[][] {}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
var RecentCounter = function () {};

var RecentCounter = function() {

};

/**
/**
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function(t) {

};
RecentCounter.prototype.ping = function (t) {};

/**
/**
* Your RecentCounter object will be instantiated and called as such:
* var obj = new RecentCounter()
* var param_1 = obj.ping(t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
class RecentCounter {
constructor() {
constructor() {}

}

ping(t: number): number {

}
ping(t: number): number {}
}

/**
* Your RecentCounter object will be instantiated and called as such:
* var obj = new RecentCounter()
* var param_1 = obj.ping(t)
*/

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @param {number[]} arr
* @param {number[][]} pieces
* @return {boolean}
*/
var canFormArray = function(arr, pieces) {
return false;
};
/**
* @param {number[]} arr
* @param {number[][]} pieces
* @return {boolean}
*/
var canFormArray = function (arr, pieces) {
return false;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function canFormArray(arr: number[], pieces: number[][]): boolean {
return false;
};
function canFormArray(arr: number[], pieces: number[][]): boolean {
return false;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} original
* @param {TreeNode} cloned
* @param {TreeNode} target
* @return {TreeNode}
*/

var getTargetCopy = function(original, cloned, target) {

};
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} original
* @param {TreeNode} cloned
* @param {TreeNode} target
* @return {TreeNode}
*/

var getTargetCopy = function (original, cloned, target) {};
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* Definition for a binary tree node.
* class TreeNode {
* val: number
* left: TreeNode | null
* right: TreeNode | null
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
* }
*/

function getTargetCopy(original: TreeNode | null, cloned: TreeNode | null, target: TreeNode | null): TreeNode | null {

};
/**
* Definition for a binary tree node.
* class TreeNode {
* val: number
* left: TreeNode | null
* right: TreeNode | null
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
* }
*/

function getTargetCopy(
original: TreeNode | null,
cloned: TreeNode | null,
target: TreeNode | null
): TreeNode | null {}
32 changes: 16 additions & 16 deletions src/main/java/problems/easy/ClimbingStairs/climbing_stairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
* @param {number} n
* @return {number}
*/
var climbStairs = function(n) {
if (1 == n) {
return 1;
}
if (2 == n) {
return 2;
}
// let values = new Array(n);
let values = Array(n).fill(-1);
values[0] = 1;
values[1] = 2;
for (let i = 2; i < n; i++) {
values[i] = values[i - 1] + values[i - 2];
}
return values[n - 1];
var climbStairs = function (n) {
if (1 == n) {
return 1;
}
if (2 == n) {
return 2;
}
// let values = new Array(n);
let values = Array(n).fill(-1);
values[0] = 1;
values[1] = 2;
for (let i = 2; i < n; i++) {
values[i] = values[i - 1] + values[i - 2];
}
return values[n - 1];
};

module.exports = { climbStairs };
module.exports = { climbStairs };
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { climbStairs } = require("./climbing_stairs");

describe.each([
[1, 1],
[2, 2],
[3, 3],
[4, 5],
[5, 8],
[1, 1],
[2, 2],
[3, 3],
[4, 5],
[5, 8],
])("climbStairs(%i) should equal %i", (input, expectedResult) => {
test(`input = {input}, returns = {expectedResult}`, () => {
expect(climbStairs(input)).toEqual(expectedResult);
});
});
test(`input = {input}, returns = {expectedResult}`, () => {
expect(climbStairs(input)).toEqual(expectedResult);
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @param {number[]} nums
* @return {number}
*/
var findShortestSubArray = function(nums) {
return 0;
};

module.exports = { findShortestSubArray };
/**
* @param {number[]} nums
* @return {number}
*/
var findShortestSubArray = function (nums) {
return 0;
};

module.exports = { findShortestSubArray };
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const { findShortestSubArray } = require("./degree_of_an_array");

describe.each([
[
[1, 2, 2, 3, 1], 2
],
[
[1, 2, 2, 3, 1, 4, 2], 6
],
])("findShortestSubArray(%o) should equal %i", (inputArray, expectedResult) => {
test(`inputArray = {inputArray} returns {expectedResult}`, () => {
expect(findShortestSubArray(inputArray)).toEqual(expectedResult);
});
});
const { findShortestSubArray } = require("./degree_of_an_array");

describe.each([
[[1, 2, 2, 3, 1], 2],
[[1, 2, 2, 3, 1, 4, 2], 6],
])("findShortestSubArray(%o) should equal %i", (inputArray, expectedResult) => {
test(`inputArray = {inputArray} returns {expectedResult}`, () => {
expect(findShortestSubArray(inputArray)).toEqual(expectedResult);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function findShortestSubArray(nums: number[]): number {
return 0;
};
function findShortestSubArray(nums: number[]): number {
return 0;
}
Loading

0 comments on commit 02a584c

Please sign in to comment.