File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 408
408
2695|[ Array Wrapper] ( ./2695-array-wrapper.js ) |Easy|
409
409
2703|[ Return Length of Arguments Passed] ( ./2703-return-length-of-arguments-passed.js ) |Easy|
410
410
2721|[ Execute Asynchronous Functions in Parallel] ( ./2721-execute-asynchronous-functions-in-parallel.js ) |Medium|
411
+ 2724|[ Sort By] ( ./2724-sort-by.js ) |Easy|
411
412
3042|[ Count Prefix and Suffix Pairs I] ( ./3042-count-prefix-and-suffix-pairs-i.js ) |Easy|
412
413
3110|[ Score of a String] ( ./3110-score-of-a-string.js ) |Easy|
413
414
3392|[ Count Subarrays of Length Three With a Condition] ( ./3392-count-subarrays-of-length-three-with-a-condition.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2724. Sort By
3
+ * https://leetcode.com/problems/sort-by/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an array arr and a function fn, return a sorted array sortedArr.
7
+ * You can assume fn only returns numbers and those numbers determine the
8
+ * sort order of sortedArr. sortedArr must be sorted in ascending order
9
+ * by fn output.
10
+ *
11
+ * You may assume that fn will never duplicate numbers for a given array.
12
+ */
13
+
14
+ /**
15
+ * @param {Array } arr
16
+ * @param {Function } fn
17
+ * @return {Array }
18
+ */
19
+ var sortBy = function ( arr , fn ) {
20
+ return arr . sort ( ( a , b ) => fn ( a ) - fn ( b ) ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments