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);
export function getDescription(text) {
    if(text.length > 10){
        return text.substring(0, 10) + "..."
    }
    return text
}
// calling 
    getProfileMode { (mode) in
            print("Mode : ", mode)
        }

func getProfileMode(completion: @escaping (String) -> Void) {
           // write firestore code here
            completion("true")
        }
    override func viewDidLoad() {
        // function calling
        querySomething { (completed) in
              print("completed :", completed)
        }
    }
    
    func querySomething(completion: @escaping (Bool) -> Void) {
        let db = Firestore.firestore()
        db.collection("collectionName").document().addSnapshotListener { (documentSnapshot, error) in
            if error != nil {
                completion(false)
                return
            }
            completion(true)
        }
    }
def byte_size(string):

  return(len(string.encode('utf-8')))

byte_size('😀’) # 4
byte_size('Hello World') # 11
#define a function 
 Def cube(num)
      #write the formula of cube
      return num*num*num
     #give the number to calculate the cube 
     cube(3)
   # print the cube of that number simply by using print command
    print(cube(3))
     “return” keyword means that function have to return          value
#define function
defall_unique(lst):

   return len(lst) == len(set(lst))
   
x = [1,1,2,2,3,2,3,4,5,6]


y = [1,2,3,4,5]


all_unique(x) # False
all_unique(y) # True
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
star

Mon Oct 31 2022 01:26:30 GMT+0000 (Coordinated Universal Time)

#return #true #substring #elipses
star

Thu Jun 09 2022 10:49:22 GMT+0000 (Coordinated Universal Time)

#ios #swift #closure #return
star

Sat Apr 02 2022 04:49:10 GMT+0000 (Coordinated Universal Time)

#ios #swift #return #completion
star

Mon Apr 20 2020 13:45:46 GMT+0000 (Coordinated Universal Time) https://towardsdatascience.com/30-helpful-python-snippets-that-you-can-learn-in-30-seconds-or-less-69bb49204172

#python #python #function #bytesize #return
star

Mon Apr 20 2020 13:32:07 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=rfscVS0vtbw&t=5s

#python #python #function #return
star

Tue Mar 31 2020 11:40:31 GMT+0000 (Coordinated Universal Time) https://towardsdatascience.com/30-helpful-python-snippets-that-you-can-learn-in-30-seconds-or-less-69bb49204172

#python #python #function #return #allunique

Save snippets that work with our extensions

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