Skip to content

Commit

Permalink
feat: "Skip" zones in range
Browse files Browse the repository at this point in the history
  • Loading branch information
201flaviosilva committed Aug 23, 2022
1 parent ca1449d commit b0d7a1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { toggleFullScreen } from "./toggleFullScreen.js";
import { sortDescending } from "./sortDescending.js";
import { sortDescendingObj } from "./sortDescendingObj.js";
import { topDownCarMovimentation } from "./topDownCarMovimentation.js";
import { Vector2 } from "./Vector2.js";
import { xnor } from "./xnor.js";
import { xor } from "./xor.js";

Expand Down Expand Up @@ -127,6 +128,7 @@ export {
sortDescending,
sortDescendingObj,
topDownCarMovimentation,
Vector2,
xnor,
xor
};
15 changes: 13 additions & 2 deletions src/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
* @example range(0, 100, 10); // [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
* @example range(0, 100, 100) // [0, 100]
* @example range(1, 100, 100) // [1]
* @example range(0, 10, 1, [{start:2,end:8}]) // [0, 1, 9, 10]
* @example range(0, 10, 1, [{start:2,end:4}, {start:7,end:8},]) // [0, 1, 5, 6, 9, 10]
*
* @param {number} start - start point to add numbers
* @param {number} end - end point to stop adding numbers
* @param {number} [step=1] - The value to increment
* @param {number[]} [skip=[]] - The values to skip
* @returns {number[]} Array of number
*/
export function range(start, end, step = 1) {
export function range(start, end, step = 1, skip = []) {
const arr = [];
for (let i = start; i < end + 1; i += step) arr.push(i);

for (let i = start; i < end + 1; i += step) {
let shouldSkip = false;
skip.forEach(({ start, end }) => {
if (i >= start && i <= end) shouldSkip = true;
});
if (!shouldSkip) arr.push(i);
}

return arr;
}
13 changes: 13 additions & 0 deletions src/screamingSnakeCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ export function stringToScreamingSnakeCase(str) { return str.replaceAll(" ", "_"
* @returns {string}
*/
export function screamingSnakeCaseToNormal(str) { return str.replaceAll("_", " ").toLowerCase(); }


/**
* Change a given text to a SCREAMING_SNAKE_CASE base text.
*
* Use {@link screamingSnakeCaseToNormal} function
*
* @see {@link screamingSnakeCaseToNormal}
*
*
* @deprecated
*/
export function screamingSnakeCaseToNormalDeprecated(str) { return str.split("_").map(s => s.toLocaleLowerCase()).join(" "); }

0 comments on commit b0d7a1d

Please sign in to comment.