Why does the position of where you add to a return value of a recursive function matter?

I’m trying to figure out why the following returns 10 correctly:

    function recurSum(n) {
      if (n <= 1)
        return n;
      return n + recurSum(n - 1);
    }
    console.log(recurSum(4)) //output 10

but when you add “n” after the recursive call in the return, you get the wrong result. The following returns 6 incorrectly

    function recurSum(n) {
      if (n <= 1)
        return n;
      return recurSum(n - 1) + n;
    }
    console.log(recurSum(4)) //output 6

Why does this happen?

How to validate a list of objects value

My array look like this:

var theset=[
    {
        "set": "1",
        "data": [
            { "field": "A", "value": "111", "check": true },
            { "field": "B", "value": "111", "check": false },
            { "field": "C", "value": "111", "check": true }     
        ]
    },
    {
        "set": "2",
        "data": [
            { "field": "A", "value": "111", "check": true },
            { "field": "B", "value": "222", "check": false },
            { "field": "C", "value": "222", "check": true }     
        ]
    },
    {
        "set": "3",
        "data": [
            { "field": "A", "value": "333", "check": true },
            { "field": "B", "value": "333", "check": false },
            { "field": "C", "value": "222", "check": true }     
        ]
    },
    {
        "set": "4",
        "data": [
            { "field": "A", "value": "444", "check": true },
            { "field": "B", "value": "333", "check": false },
            { "field": "C", "value": "444", "check": true }     
        ]
    }
];

What I want to do is validate the “value” of “field” with other set if the “check” is true.

The result is to return a true if there is a duplication of “value” in the set. The example will return a true because

  • set 1: having duplicate value for field A with set 2
  • set 2: having duplicate value for field A with set 1, duplicate value for field C with set 3
  • set 3: having duplicate value for field C with set 2

so far I tried to do for loop on the list but this will have a lot of nested loop which is not efficient.

for(var i=0; i<theset.length; i++){
    var checking = theset[i].data;
    for(var j=0; j<checking.length; j++){
        if(checking[j].check){
            for(var k=0; k<theset.length; k++){
                if(k!=i){
                    var checking2 = theset[k].data;
                    for(var l=0; l<checking2.length; l++){
                     ...
                    }
                }
            }         
        }
    }
}

Can anybody help me?

I cannot add meteor package ‘akryum:vue-sass’, I found the error while adding packages: While loading package akryum:[email protected]:

I’m new to Meteor. Can anyone help me in adding meteor package.
I have used Node version 14.19.0 and I got error while adding akryum:vue-sass package.
I tried changing node version to older version but I still facing error belows.

$ meteor add akryum:vue-sass

=> Errors while adding packages:

                                           While loading package akryum:[email protected]: error: Command failed:

/home/bigsoft/.meteor/packages/meteor-tool/.2.5.1.1c8dly1.o32v++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/npm
rebuild –update-binary Cannot download
“https://github.com/sass/node-sass/releases/download/v4.12.0/linux-x64-83_binding.node”:

HTTP error 404 Not Found

Hint: If github.com is not accessible in your location try setting a
proxy via HTTP_PROXY, e.g.

export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

npm config set proxy http://example.com:8080 gyp info it worked if it
ends with ok gyp verb cli [ gyp verb cli
‘/home/bigsoft/.meteor/packages/meteor-tool/.2.5.1.1c8dly1.o32v++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node’,
gyp verb cli
‘/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/node-gyp/bin/node-gyp.js’,
gyp verb cli ‘rebuild’, gyp verb cli ‘–verbose’, gyp verb cli
‘–libsass_ext=’, gyp verb cli ‘–libsass_cflags=’, gyp verb cli
‘–libsass_ldflags=’, gyp verb cli ‘–libsass_library=’ gyp verb cli
] gyp info using [email protected] gyp info using [email protected] | linux |
x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb
clean removing “build” directory gyp verb command configure [] gyp
verb check python checking for Python executable “python2” in the PATH
gyp verb which failed Error: not found: python2 gyp verb which
failed at getNotFoundError
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:13:12)
gyp verb which failed at F
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:68:19)
gyp verb which failed at E
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:80:29)
gyp verb which failed at
/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:89:16
gyp verb which failed at
/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/isexe/index.js:42:5
gyp verb which failed at
/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/isexe/mode.js:8:5
gyp verb which failed at FSReqCallback.oncomplete (fs.js:191:21)
gyp verb which failed python2 Error: not found: python2 gyp verb
which failed at getNotFoundError
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:13:12)
gyp verb which failed at F
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:68:19)
gyp verb which failed at E
(/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:80:29)
gyp verb which failed at
/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/which/which.js:89:16
gyp verb which failed at
“rebuild” “–verbose” “–libsass_ext=” “–libsass_cflags=”
“–libsass_ldflags=” “–libsass_library=” gyp ERR! cwd
/home/bigsoft/.meteor/packages/akryum_vue-sass/.0.1.2.bp32sy.5635m++os+web.browser+web.browser.legacy+web.cordova/plugin.vue-component-sass.os/npm/node_modules/meteor/vue-component-sass/node_modules/.temp-1q712kk.2pt1/node_modules/node-sass gyp ERR! node -v v14.18.1 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok
Build failed with error code: 1 npm ERR! code ELIFECYCLE npm ERR!
errno 1 npm ERR! [email protected] postinstall: node scripts/build.js
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the
[email protected] postinstall script. npm ERR! This is probably not a
problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
/home/bigsoft/.npm/_logs/2022-02-21T04_25_07_383Z-debug.log


that is all the error messages. Thanks.

how to get an iframe in document.write

i have tried this:

<script>
  function aboutblank(){
  let win = window.open();
  win.document.write("<iframe src="/Offline_Download_Version.html"></iframe>")}
                     </script> 

<button onclick="aboutblank()">Click me</button>

but it didnt work, ive also tried putting the actual file url, the plain code url, the plain code, and a few more things, but i cant figure it out.

i am trying to put home-schoology.github.io/Offline_Download_Version.html into this script in an iframe, so how would i go along doing this? (it is supposed to open in an about:blank tab and open an iframe with the html)

Uncaught TypeError: Cannot read properties of undefined (reading ‘length’)

I am developing a react app, but i am facing this error-> “Uncaught TypeError: Cannot read properties of undefined (reading ‘length’)”. how to fix this?
my code is:

import React from "react";
import { Grid, CircularProgress } from "@material-ui/core";
import Post from "./Post/Post";
import useStyles from "./styles";
import { useSelector } from "react-redux";

const Posts = () => {
  const posts = useSelector((state) => state.Posts);
  const classes = useStyles();

  console.log(posts);
  return (!posts.length ? <CircularProgress/> :(
   <Grid className={classes.container} container alignItems="stretch" spacing={3}>
      {
        posts.map((post)=> (
              <Grid key={post._id} item xs={12} sm={6}>
                <Post post = {post} />
              </Grid>
        ))
      }

   </Grid>
 )
  );
};

export default Posts;

Zooming not Disabling Button in Leaflet

This is what I’m doing, when I click the “Enter Building” text it will zoom in to the specific coordinates and it will show the buttons for different floors (1, 2, 3, 4). This is working right now.

enter image description here

This is what it looks like when I click “Enter Building”

enter image description here

When I click the Zoom Out in the top left corner, it should hide/disable the floor buttons. But my problem is, it’s not working. My other problem is whenever I click the “Enter Building” again, it duplicates the Floor Buttons.

here’s the code:

layer.on("popupopen", () => {
    $("#enter-btn").click(function () {  
    map.setView(
        [
          layer.feature.geometry.coordinates[1],
          layer.feature.geometry.coordinates[0],
        ],
        25
      );

      var floor1 = L.easyButton(
        "<strong>1</strong>",
        function () {
          zoomLevel();
        },
        {
          position: "bottomleft",
        }
      ).addTo(map);

      var floor2 = L.easyButton(
        "<strong>2</strong>",
        function () {
          zoomLevel();
        },
        {
          position: "bottomleft",
        }
      ).addTo(map);

      var floor3 = L.easyButton(
        "<strong>3</strong>",
        function () {
          zoomLevel();
        },
        {
          position: "bottomleft",
        }
      ).addTo(map);

      var floor4 = L.easyButton(
        "<strong>4</strong>",
        function () {
          zoomLevel();
        },
        {
          position: "bottomleft",
        }
      ).addTo(map);

      // remove building marker
      markerClusters.removeLayer(buildings);
      // sync sidebar data
      syncSidebar();
      // close sidebar
      animateSidebar();
      
      // disable or enable floor button
      function zoomLevel() {
        map.on("zoomend", function (e) {
          var max = 21,
            current = map.getZoom();
          if (current < max) {
            floor1.disable();
            floor2.disable();
            floor3.disable();
            floor4.disable();
          }
          if (current >= max) {
            floor1.enable();
            floor2.enable();
            floor3.enable();
            floor4.enable();
          }
        });
      }
    });
  });

I’m very sorry if my explanation is not very clear.

WaveSurfer The ScriptProcessorNode is deprecated. Use AudioWorkletNode instead, how to fix?

Cannot create wavesurfer on click, how to fix this? on click get this error

[Deprecation] The ScriptProcessorNode is deprecated. Use AudioWorkletNode instead.

https://prnt.sc/WEpR0ECmFtHj

onClick(initAudioReview, e => {
    prs = getParent(e.currentTarget, 1);
    waveTrack = getElement('.wave-track', prs);
    audioTrackSource = getAttribute(waveTrack, 'data-audio_source', true);
    audioTrackContainer = getAttribute(waveTrack, 'data-audio_container', true);


    wavesurfer = WaveSurfer.create({
        container: audioTrackContainer,
        waveColor: '#434242',
        progressColor: '#34B249',
        barWidth: 2,
        barGap: 2,
        height: 78,
        barHeight: 1,
        responsive: true,
        hideScrollbar: true,

    });
    wavesurfer.load(audioTrackSource);
    wavesurfer.onclick = function(e){
        wavesurfer.playPause();

    };


    getElement('.wave-track__duration', prs).textContent = wavesurfer.getDuration();                
})

vscode wont run nvm packages without me rerunning the .zsh_profile command everytime i restart vscode

I know a lot of other people have had this issue but i cant seem to make it work.

if i dont run these commands in the vscode terminal everytime i open it it wont run npx,npm or nvm.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

i also added these commands to my .zsh_profile and added "terminal.integrated.shellArgs.linux": "-L", to my settings.json folder inside Library/Application Support/Code/User/settings.json

i restarted vscode and npm,nvm,npx still wont run.
enter image description here

after that i switched terminal profiles in vscode back to bash and it works to my surprise but other commands like ls find wont work and gives me a weird error so i cant use the bash in my vscode terminal even if i wanted to.
enter image description here

any suggestions on what should i do next?

Typescript array reduce with async/await showing type mismatch error

Seem to be having some type issue by using async/await with .reduce()

I have to call one async function inside the reduce with proper types but I can’t figure out why Anyone pls help me

interface Person {
  name: string;
  age: number;
}

const persons: Person[] = [
  { name: 'John', age: 30 },
  { name: 'Alice', age: 45 },
];

function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

const ageByPerson: Person[] = persons.reduce<Person[]>(
  async (result, person) => {
    await sleep(4000);
    return result.concat({
      age: person.age,
      name: person.name,
    });
  },
  []
);
console.log('age ', ageByPerson);

Without interface is working fine But when I am using with interface I can’t figure it out

Interact.js doesn’t works with sotable.js in Firefox [closed]

I’m using interact.js and sortable.js libraries.

Everything goes fine in Chrome and Edge but un Firefox Is like just sortable.js Is working…however when i change to enable touch simulation mode Is interact.js working AND not sortable.js.

Apparently Firefox Is allowing just 1 of 2 libraries works at the same Time

I see the console and there are no error messages.

What Kind of software tools can i use to debug this ???

Why Is working fine in Chrome and Edge but not in Firefox ?

Why does Visual Code create hidden files, and how do I stop it?

Everything that touches Visual Code gets copied and then displayed on the side as a hidden file… but annoying because it’s actually not hidden and stressing my OCD. How do I prevent visual code from making copies of every single file in the first place?

Thank you.

To clarify, I want Visual Code to NOT make any copy. I do not need additional files. I could delete all of them, but to do that every single time I use VS… well… you get it. How do I stop Visual Code from doing this.

Sorry I have to repeat myself, some people do not like answering questions on a platform for people seeking answers.

Howl Js: How to Play the same button after Pause?

I am creating a sound board with a mapped array.
I have a onClick Handler which changes the colour of the button that is active/playing and Play/Pauses.

Currently I can pause the ‘active’ button but cannot restart the track for that button.
I can stop playing that track if I press on a different button to play that buttons track.

Just looking for some help on how to Play the same button after I paused it.

Thanks 🙂

const handleClick = (beat: string, index: number ) => {

    if (activeIndex === isActive) {
        setIsActive(!isActive);
        activeSound.play();
    }


    if (activeSound) {
        activeSound.stop();           
    } 

    if (!activeSound && activeIndex === isActive) {
        const newSound = createSound(beat);
        newSound.play();
        setActiveSound(newSound);
    }

    if (activeIndex !== index) {
        const newSound = createSound(beat);
        newSound.play();
        setActiveSound(newSound);
    }
    setActiveIndex(index);
}
return (
    <Container>
        <Title> Melody </Title>
        <Grid>
            {
                melodyData.map((beat, index: number) => {
                    return <Button key={index} $isActive={activeIndex === index} onClick={() => handleClick(beat.src, index)}>{beat.title}</Button>
                })
            }
        </Grid>
    </Container>
)

};

How do I return a json value from an axios api request?

I want to return a some information in a json format so I can assign variables to them. I’m using Axios to get some json info on movies but can’t seem to assign a variable to the data, as I always get ‘undefined’ in the output. Any fixes?

Here’s my code, as you can see I’m trying to return something from the function then assign a value to it.

function getMovie(movie){
    axios.get('http://www.omdbapi.com?t='+movie+'&apikey='+APIKEY)
        .then((response) => {
            console.log(response.data);
            let info = response.data;
            return response.data;
        })
        .catch((error)=>{
            console.log(error);
        })
};

let movieInfo = getMovie('Dune');
console.log(movieInfo);