Second Value

Second Value

Second Value is when we return the middle value and unique values.


##For Example
[1] => 1
[3,2,88,3,-11,67,7] => [-11,2,3,7,67,88]

##



function secondValue(arr) {
	let values = [...new Set(arr)].sort((a,b) => a - b);
	if(values.length < 2) {
		return values
	}
}



function secondValue(arr){

First we create a function called secondValue and pass an argument called arr.



let values = […new Set(arr)];

We create variable values and we use Set data structure to eliminate the doubles



let values = […new Set(arr)].sort((a,b) => a - b);



We attach the sort method to sort in ascending order

comments powered by Disqus