Write a function called minSubArrayLen which accepts two parameters - an array of positive integers and a positive integer. This function should return the minimal length of a contiguous subarray of which the sum is greater than or equal to the integer passed to the function. If there isn't one, return 0 instead.
This file contains hidden or 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 router = require('express').Router() | |
const {User, Subscription} = require('../db/models') | |
const webPush = require('web-push') | |
module.exports = router | |
router.post('/', async (req, res, next) => { | |
try { | |
// Our app has 4 defferent option for reminder, so depends on | |
// which reminder gets called, payload is changed. |
This file contains hidden or 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
import React from 'react' | |
import {connect} from 'react-redux' | |
import {handleSubscription} from '../../public/main' | |
export class UserHome extends React.Component { | |
//other code are omited | |
async componentDidMount() { | |
try { | |
await handleSubscription(this.props.user) |
This file contains hidden or 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 router = require('express').Router() | |
const {User, Subscription} = require('../db/models') | |
module.exports = router | |
router.post('/:userId', async (req, res, next) => { | |
try { | |
const userId = req.params.userId | |
const data = req.body | |
//subscription object has 3 properties and the value of the 'keys' property is a nested object, so | |
//to store the value in PostgreSQL, it has to be stringified. |
This file contains hidden or 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
export const handleSubscription = (user) => { | |
'use strict' | |
const axios = require('axios') | |
let isSubscribed = false | |
let swRegistration = null | |
let anyReminder = false | |
//user object holds the user's reminder opt-in status as boolean. | |
//checking if the user opted-in any of our reminder option | |
if (Object.values(user).some((val) => val === true)) anyReminder = true |
This file contains hidden or 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
self.addEventListener('push', (event) => { | |
let body | |
if (event.data) { | |
//You can set an original message by passing it on the event. | |
body = event.data.text() | |
} else { | |
body = 'Default body' | |
} | |
const options = { |