Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#27-array-standalone #29

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
45 changes: 45 additions & 0 deletions staff/ventura-rodriguez/array-standalone/at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function at(array, index) {}

{
const result1 = at(["a", "b", "c", "d", "e"], 2);
const nativeResult1 = ["a", "b", "c", "d", "e"].at(2);
console.assert(result1 === nativeResult1, {
result: result1,
message: "Test 1 no pasado",
});

const result2 = at(["a", "b", "c", "d", "e"], -1);
const nativeResult2 = ["a", "b", "c", "d", "e"].at(-1);
console.assert(result2 === nativeResult2, {
result: result2,
message: "Test 2 no pasado",
});

const result3 = at(["a", "b", "c", "d", "e"], 10000);
const nativeResult3 = ["a", "b", "c", "d", "e"].at(10000);
console.assert(result3 === nativeResult3, {
result: result3,
message: "Test 3 no pasado",
});

const result4 = at(["a", "b", "c", "d", "e"], -100);
const nativeResult4 = ["a", "b", "c", "d", "e"].at(-100);
console.assert(result4 === nativeResult4, {
result: result4,
message: "Test 4 no pasado",
});

const result5 = at(["a", "b", "c", "d", "e"], null);
const nativeResult5 = ["a", "b", "c", "d", "e"].at(null);
console.assert(result5 === nativeResult5, {
result: result5,
message: "Test 5 no pasado",
});

const result6 = at(["a", "b", "c", "d", "e"], "a");
const nativeResult6 = ["a", "b", "c", "d", "e"].at("a");
console.assert(result6 === nativeResult6, {
result: result6,
message: "Test 6 no pasado",
});
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
52 changes: 52 additions & 0 deletions staff/ventura-rodriguez/array-standalone/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function map(array, callback) {
const result = [];
for (let i = 0; i < array.length; i++)
result[i] = callback(array[i], i, array);
return result;
}

{
function isArrayEqual(arr1, arr2) {
if (arr1.length !== arr2.length) return false;

let result = true;
let i = 0;
while (i < arr1.length || result === false) {
if (arr1[i] !== arr2[i]) result = false;
i++;
}
return result;
}

debugger;
const array1 = [1, 2, 3];
const fn1 = (element) => element * 2;
const result1 = map(array1, fn1);
const nativeResult1 = array1.map(fn1);

console.assert(isArrayEqual(result1, nativeResult1), {
result: result1,
message: "Test 1 no pasado",
});

const array2 = [1, 2, 3];
const fn2 = (element, index) => element * index;
const result2 = map(array2, fn2);
const nativeResult2 = array2.map(fn2);

console.assert(isArrayEqual(result2, nativeResult2), {
result: result2,
message: "Test 2 no pasado",
});

const array3 = [1, 2, 3];
const fn3 = (element, index, array) =>
element * array[array.length - index - 1];
const result3 = map(array3, fn3);
const nativeResult3 = array3.map(fn3);

console.assert(isArrayEqual(result3, nativeResult3), {
result: result3,
message: "Test 3 no pasado",
});
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.