This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isIsogram(word){ | |
if (word === "") { | |
return false; | |
} else { | |
return !/(\w).*\1/i.test(word); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShoppingCart: | |
def __init__(self): | |
self.total = 0 | |
self.items = {} | |
def add_item(self, item_name, quantity, price): | |
self.items[item_name] = self.items.get(item_name, 0) + quantity | |
self.total += (price*quantity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isIsogram(word) { | |
if (word == "" || word <= 0) { | |
return false; | |
} | |
word.toLowerCase(); | |
var i, j; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_duplicates(word): | |
new_word = "".join(sorted(dict.fromkeys(word))) | |
return (new_word, len(word)-len(new_word)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_sort(list_numbers): | |
e_list = [] | |
o_list = [] | |
for x in list_numbers: | |
if x % 2 == 0: | |
e_list.append(x) | |
else: | |
o_list.append(x) | |
o_list.sort() | |
e_list.sort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeDuplicates(str) { | |
//remove all non alphabets | |
var expression = /[^a-zA-Z]/g; | |
var unique = []; | |
var repeated = []; | |
var obj = { | |
uniques: [unique], | |
duplicates: [], | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sort(arr) { | |
arr.sort( function(a, b) { | |
return b.length - a.length;// || //sort by length, if equal then | |
// a.localeCompare(b); //sort by dictionary order | |
}); | |
return arr; | |
} | |
sort(["Abia", "Adamawa", "Anambra", "Akwa Ibom", "Bauchi", "Bayelsa", "Benue", "Borno", "Cross River", "Delta", "Ebonyi", "Enugu", "Edo", "Ekiti", "Gombe", "Imo", "Jigawa", "Kaduna", "Kano", "Katsina", "Kebbi", "Kogi", "Kwara", "Lagos", "Nasarawa", "Niger", "Ogun", "Ondo", "Osun", "Oyo", "Plateau", "Rivers", "Sokoto", "Taraba", "Yobe", "Zamfara"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longest(sentence) { | |
var str = sentence.split(" "); | |
var longest = 0; | |
var word = null; | |
str.forEach(function(str) { | |
if (longest < str.length) { | |
longest = str.length; | |
word = str; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShoppingCart { | |
constructor () { | |
this._total = 0; | |
this._item = {}; | |
} | |
addItem(itemName, quantity, price) { | |
this._total += price; | |
//confirm if you should use dot notation or bracket notation to access itemName. | |
item.[itemName] = quantity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShoppingCart { | |
constructor(){ | |
this.total = 0; | |
this.items = { }; | |
} | |
addItem(itemName, quantity, price) { | |
let cost = quantity * price; | |
this.total = this.total + cost; | |
this.items[itemName] = quantity; |
OlderNewer