Skip to content

Instantly share code, notes, and snippets.

View steph-crown's full-sized avatar
💻
Open to work

Stephen Emmanuel steph-crown

💻
Open to work
View GitHub Profile
@steph-crown
steph-crown / main.dart
Created October 8, 2020 23:00
Loops through a list of numbers and prints out the squares of each numbers
void main() {
List<num> numList = [5,8,9,6,4];
numList.forEach((x) => print (x * x));
}
@steph-crown
steph-crown / main.dart
Created October 8, 2020 23:07
Prints all.letters in.my name
void main() {
String name = 'Steph Crown';
for (var j in name) {
print(name);
}
}
@steph-crown
steph-crown / main.dart
Created October 9, 2020 07:15
Prints out all the letters in my name
void main() {
String name = 'Steph Crown';
for (var j in name.split('')) {
print(j);
}
}
@steph-crown
steph-crown / main.dart
Created October 9, 2020 07:42
Uses while loop to print all letters in my name
void main(){
String name = 'Steph Crown';
int counter = 0;
while (counter < name.length) {
print(name[counter]);
++counter;
}
}
///A palindrome checker
bool checkPalindrome(String str) {
return str == reverseStr(str);
}
///A string reverser
String reverseStr(String str) {
return str.split('').reversed.join();
}
@steph-crown
steph-crown / main.dart
Created October 16, 2020 18:06
Palindrome checker
///A palindrome checker
bool checkPalindrome(String str) {
return str == reverseStr(str);
}
///A string reverser
String reverseStr(String str) {
return str.split('').reversed.join();
}
@steph-crown
steph-crown / main.dart
Created October 16, 2020 19:52
Checks if a list is a subset of another list
///A function that checks if a list is a subset of another
bool subsetChecker(List list1, List list2) {
//Iterates through first array and checks if all element are in second array
return list1.every((item) => list2.contains(item));
}
void main() {
@steph-crown
steph-crown / main.dart
Created October 16, 2020 20:27
Calculates product of prime factors of a number
///Checks if a number is prime
bool checkPrime(x) {
int factors = 0;
int i = 1;
//He number of factors of the number
while (i <= x) {
factors = x % i == 0 ? factors + 1 : factors;
i++;
}
@steph-crown
steph-crown / index.js
Last active January 28, 2022 12:19
A script to register a service worker
// Checks if we can use serviceWorker.
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("sw.js")
.then((registration) => {
// The registration wass successful
console.log("Service worker registered");
console.log(registration);
})
@steph-crown
steph-crown / sw.js
Last active January 28, 2022 13:24
A service worker file
// Listens to an install event
self.addEventListener("install", (event) => {
event.waitUntil(
// We try to open a cache named "assets".
// If it does not exist, a new one will be created and named "assets"
caches.open("assets").then((cache) => {
// Add an array of path to files you want to add to cache
return cache.addAll([
"./",
"./css/index.css",