npm i same.js
const { Same } = require("Same");
var same = new Same();
same.insert(1, "one"); // inserts 1 in the first array and "one" in the second array
console.log(same.over(1) + "\n" + same.over("one")); // outputs the overwritten element for the index of the value 1 and the overwritten element for the index of the value "one"
async function main() {
same.insert(1, "one"); //
same.insert(2, "two"); // inserts many values in the Same
same.insert("uno", 1); //
console.log(await same.has(1)); // checks if the Same has the value 1 and outputs an array of objects containing the index and the number of array where the value 1 is stored
}
main() // calls an async function (THE MODULE has() MUST BE AWAITED)
async function main() {
let ar1 = [0, 1, 2, 3]; // creates a 4-indexed array
let ar2 = ["zero", "one", "two"]; // creates a 3-indexed array
same.insert(ar1, ar2); // inserts the arrays in the Same; since ar2 has one value less than ar1, in the second array there will be an empty space
await same.replaceUnd(["three"]) // the empty space is overwritten with the string "three"
console.log(same);
}
main() // calls the async function (THE MODULE replaceUnd() MUST BE AWAITED)
same.insert(1, "one");
same.insert(2, "two");
same.replace(1, false, "one", 1); // replaces the indexes in the Same of the value 1 with "one" in the first array and 1 in the second
same.replace(1, true, "two", 2); // replaces the indexes 1 in the Same with "two" in the first array and 2 in the second
console.log(same);
for (let i = 0; i < 10; i++) {
same.insert(i, i - i * 2); // inserts in the first array every number from 0 to 9 and in the second array every number from 0 to -9
}
console.log(same);
console.log("\n\n\n");
console.log(same.cut(2, 4)); // outputs the object with two arrays with every element of the first and second array inside the indexes 2 and 4
for (let i = 0; i < 10; i++) {
same.insert(i, i - i * 2); // inserts in the first array every number from 0 to 9 and in the second array every number from 0 to -9
}
same.insert("hello", "ciao") // inserts in the first array the string "hello" and in the second array the string "ciao"
console.log(same);
console.log("\n\n\n");
same.remove(0); // removes the indexes 0 for both arrays
same.remove("hello") // removes the indexes of the value "hello" for both arrays
same.remove([1, 3, 5, 7, 9], false) // removes every odd number from the arrays
console.log(same);
async function main() {
for (let i = 0; i < 10; i++) {
same.insert(i, i - i * 2); // inserts in the first array every number from 0 to 9 and in the second array every number from 0 to -9
}
await same.forEach((element) => { // starts to loop throught every element in the same
console.log(element) // every time the loop executes it outputs the element
})
}
main() // calls and async function (THE MODULE forEach() MUST BE AWAITED)
async function main() {
await same.charNumbInsert(-4, 9); // inserts in the first array every number from -4 to 9, translates them into spoken language and inserts the strings in the second array
await same.forEach((element) => {
console.log(element); // outputs every element in the Same
})
}
main() // calls an async function (THE MODULE charNumbInsert() MUST BE AWAITED)
Same
new Same();
Properties = {
first,
second,
timestamp
}
Methods = {
insert(),
over(),
has(),
replaceUnd(),
replace(),
cut(),
remove(),
forEach(),
cherNumbInsert(),
NoValue(),
NoFn(),
_0Value()
}
- .first
- .second
- .timestamp
-
.insert(firstValue, secondValue)
To Note: When both firstValue and secondValue are objects or arrays, insert() will automatically add every property or element in the next indexes
Parameter Type Description firstValue any The value stored in the first array of the Same secondValue any The value stored in the second array of the Same -
.over(value)
Overwrites the value into the corresponding one; if there are more indexes with the same value, it returns an array of its overwritten values
Parameter Type Description value any The value in the same index of its correspoding -
.has(value)
Parameter Type Description value any The value to check -
.replaceUnd(elements)
Parameter Type Description elements any[] The array of elements to replace in order -
.replace(index, isIndex, firstElement, secondElement)
Parameter Type Description index number or any The index of the variables to replace (it can be one of the values itself) isIndex boolean Checks if the number inserted as index is an index or a variable inside the Same firstElement any The value to replace in the first array secondElement any The value to replace in the second array -
.cut(firstIndex, lastIndex)
Parameter Type Description firstIndex number or any The index of the Same from where the selection starts (it may be the value of the index itself) lastIndex number or any The index of the Same form where the selection ends (it may be the value of the index itself) -
.remove(value, isIndex, spaces)
Parameter Type Description value number or any The index from where the selection starts; it can be the value of the index itself; if it's an array of values, spaces can be omitted isIndex boolean Decides if the value must be an index of the array or the value of an element spaces number The number of indexes that will be removed after the first one (default: 1) - .length()
-
.forEach(callback)
Executes a code for every elements inside the first array of the Same first, and then in the second one
Parameter Type Description callback Function The code that will be executed with every elements in the Same as parameter -
.charNumbInsert(from, to)
Translates every number between the parameters (included) from decimal to spoken language and inserts the numbers in the first array, and the translations in the second one
Parameter Type Description from number The number from where the translation will start to number The number from where the translation will end - .NoValue()
- .NoFn()
- ._0Value()
cheeseburger006