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
const selectionSort = (nums) => { | |
checkLoopInvariant(nums, input, 0) //check during initialization | |
for (let i = 0; i < nums.length - 1; i++) { | |
checkLoopInvariant(nums, input, i) //check at each iteration | |
} | |
checkLoopInvariant(nums, input, nums.length) //check at the | |
return nums | |
} |
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
let smallest = nums[i] | |
let swapIndex = i | |
// Search the remainder of the array for the smallest number | |
for (let j = i + 1; j < nums.length; j++) { | |
if (nums[j] < smallest) { | |
smallest = nums[j]; | |
swapIndex = 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
// see repo for full code | |
boolean milk; | |
boolean soy; | |
boolean mocha; | |
boolean whip; | |
// and their getters and setters | |
public int cost() { |
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
public abstract class Beverage { | |
String desc = "unknown beverage"; | |
public String getDescription() { | |
return desc; | |
} | |
public abstract int cost(); | |
} |
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
public class DarkRoast extends Beverage { | |
public DarkRoast() { | |
desc = "Dark roast"; | |
} | |
@Override | |
public int cost() { | |
return 20; | |
} | |
} |
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
public abstract class CondimentDecorator extends Beverage { | |
Beverage beverage; | |
public abstract String getDescription(); | |
} |
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
public class Mocha extends CondimentDecorator { | |
public Mocha(Beverage b) { | |
beverage = b; | |
} | |
@Override | |
public String getDescription() { | |
return beverage.getDescription() + ", Mocha"; | |
} | |
@Override | |
public int cost() { |
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
public class Mocha extends CondimentDecorator { | |
public Mocha(Beverage b) { | |
beverage = b; | |
} | |
@Override | |
public String getDescription() { | |
return beverage.getDescription() + ", Mocha"; | |
} | |
@Override | |
public int cost() { |
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
# -*- coding: utf-8 -*- | |
import scrapy | |
class ElectronicsSpider(scrapy.Spider): | |
name = "electronics" | |
allowed_domains = ["www.olx.com.pk"] | |
start_urls = ['http://www.olx.com.pk/'] | |
def parse(self, response): |
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
from scrapy.spiders import CrawlSpider, Rule | |
from scrapy.linkextractors import LinkExtractor | |
class ElectronicsSpider(CrawlSpider): | |
name = "electronics" | |
allowed_domains = ["www.olx.com.pk"] | |
start_urls = [ | |
'https://www.olx.com.pk/computers-accessories/', | |
'https://www.olx.com.pk/tv-video-audio/', | |
'https://www.olx.com.pk/games-entertainment/' |
OlderNewer