Snippets Collections
const prices = [400.50, 3000, 99.99, 35.99, 12.00, 9500];


// Sorting books by their rating: // use slice to copy the array
const acscendingsOrders = prices.slice().sort((a, b) => a.toFixed(2) - b.toFixed(2))
const descendingOrders = prices.slice().sort((a, b) => b.toFixed(2) - a.toFixed(2))

/** The indexOf() method
	Returns the position of the first occurrence of a value in a string.
	The indexOf() method returns -1 if the value is not found.
	The indexOf() method is case sensitive.
  */


function isValidPassword(password, username) {
	if (
		password.length < 8 ||
		password.indexOf(' ') !== -1 ||
		password.indexOf(username) !== -1
	) {
		return false;
	}
	return true;
}

/** or */


function isValidPassword(password, username) {
	const tooShort = password.length < 8;
	const hasSpace = password.indexOf(' ') !== -1;
	const tooSimilar = password.indexOf(username) !== -1;
	if (tooShort || hasSpace || tooSimilar) return false;
	return true;
}
function betweenYears(yearStart, yearEnd){
    return function(number){
          if(number >= yearStart && number <= yearEnd){
              return number
          }
          return false
    }
}

const myYear = betweenYears(1900, 1999);
myYear(1978);
star

Wed Apr 12 2023 05:58:05 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering
star

Wed Apr 12 2023 01:00:20 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering
star

Wed Apr 12 2023 00:20:59 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension