Skip to content
Closed
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
Add apply transform over each element in array problem
  • Loading branch information
sumangopalrao committed Aug 28, 2023
commit 906737f3f0bbb73ec0ce84fd343835e12ecd39fd
12 changes: 12 additions & 0 deletions javascript/2635-apply-transform-over-each-element-in-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {number[]} arr
* @param {Function} fn
* @return {number[]}
*/
var map = function(arr, fn) {
const result = [];
for (let index = 0; index < arr.length; index++) {
result.push(fn(arr[index], index));
}
return result;
};