Skip to content

第 161 题:用最精炼的代码实现数组非零非负最小值 index #582

Open
@greatInvoker

Description

@greatInvoker
const arr = [10, 21, 0, -7, 35, 7, 9, 23, 18];

function getIndex(arr) {
	let min = Infinity;
	arr.forEach((v) => {
		v > 0 && v < min && (min = v);
	});
	return arr.indexOf(min);
}

console.log(getIndex(arr));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions