MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / leastLarger

Function leastLarger

Codewars_problems/Least Larger/solution.js:1–14  ·  view source on GitHub ↗
(array, n)

Source from the content-addressed store, hash-verified

1function leastLarger (array, n) {
2 const larger = [];
3 for (let i = 0; i < array.length; i++) {
4 if (array[i] > array[n]) {
5 larger.push(array[i]);
6 }
7 }
8 const min = Math.min(...larger);
9 return array.indexOf(min);
10
11 //larger contains the elements of array which are larger then array[n]
12 //min is the minimum of larger's elements
13 //the function returns with the min's index in array
14}
15
16console.log(leastLarger([-1, -6, -4, -7, 9, -3, 6, 0], 2));
17

Callers 1

solution.jsFile · 0.85

Calls 2

minMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected