Action

Vocab Display

Posted by @Joel_Arnold, Last update over 3 years ago

Vocab Practice

I wanted to work at remembering and incorporating better vocabulary words into my daily usage. When I encounter a word I want to remember I drop it at the end of a draft (you can use iOS Shortcuts to just append…). This action will (1) add an index number to the end of each word, (2) alphabetize the list and (3) randomly choose out three words to be repeated right after the title. (4) It also updates the index so that each time you see a word it is that much less likely to reappear.
The point is to then add these as a list widget. Set the parameter in the widget to [[line|3..5]] to select out those lines.
I also use iOS shortcuts to automate running the widget every morning at 4 AM so that I get new words every day.
If you want to further customize (how many words to display, etc), adjust the numbers at the top of the script. Instructions are there.
The first time you creat this you will also need to insert 3 dummy words (which will be replaced) after the title and before the list of vocab words begins. For me this looks like this:
Title

dummy word
dummy word
dummy word

List of actual vocab words begins here.

@Joel_Arnold

Steps

  • script

    // The normal parameter to set in the widget is widget[[line|3..5]]
    
    // Here are two factors to adjust.
    
    // Tally—Adjust how much you want to increase their tally score. The higher the number, the more likely it will call everyone once before calling on them again. If this is set to 1, someone might get called 5-6 times while another person is never called at all. For my purposes , 5 is working well.
    
    // howManyWords—Lets you toggle how many words the script will drop at the top of the list, hence how many will appear in your widget. Be sure to adjust the parameter you use in your widget accordingly. And whatever number you choose here, you need to leave that many empty lines +2 after the title.
    
    var tally = 5;
    var howManyWords = 3;
    
    // ** Pulls in the draft
    
    let originalText = draft.content;
    
    // Separates the title and the list of names
    
    var splitLines = originalText.split("\n");
    var title = splitLines.slice(0, 1);
    var namesSplit = splitLines.slice((howManyWords + 3),);
    let fullArray = []
    
    // Alphebatize the list of words
    namesSplit = namesSplit.sort();
    
    
    
    // Function to put these lines into an object
    
    function createPersonRecord(fullLine) {
    	var scoreArray = fullLine.split(", ");
    	if (!scoreArray[1]){
    	scoreArray[1] = 1
    	}
    	let personObject = {"name": scoreArray[0], "timesCalled": parseInt(scoreArray[1])};
    	return personObject;
    }
    
    // ** Turns all of the listed names into objects nested in an array. It iterates through and puts each one into this format as an object, then pushes it to the array.
    
    for (var i = 0; i < namesSplit.length; i++) {
    	fullArray.push(createPersonRecord(namesSplit[i]));
    }
    
    
    // ** iterates three times (or whatever chosen above) to add three words to the top of the Draft
    
    var chosenWordsList = "";
    
    for (var i = 0; i < howManyWords; i++) {
    	chosenWordsList = chosenWordsList + "\n" + chooseWord();
    //	chosenWordsList.push(chooseWord());
    
    }
    
    
    // Function to choose a random number, choose a student from the array and update their score.
    function chooseWord() {
    
    // Adds up the total scores of all students so far as an inverse of their times called number
    let sumOfTimesCalled = 0
    for (var i = 0; i < namesSplit.length; i++) {
    	sumOfTimesCalled += 1 / fullArray[i].timesCalled;
    }
    
    // Takes the random number generated and multiplies it by the total scores
    let test = Math.random()
    let chosenWordDecimal = Math.random() * sumOfTimesCalled;
    let chosenWord = "";
    
    // Picks out the correct word from the array
    let testSum = 0
    for (var i = 0; chosenWordDecimal > testSum; i++) {
    	testSum += 1 / fullArray[i].timesCalled;
    	chosenWord = fullArray[i].name ;
    	chosenWordIndex = i
    }
    
    // Adds one to their score
    fullArray[chosenWordIndex].timesCalled = fullArray[chosenWordIndex].timesCalled + tally;
    chosenWordsList = chosenWordsList + "\n" + chosenWord;
    
    return chosenWord;
    
    // End of the function for choosing a word.
    }
    
    let updatedList = "";
    // Recreates the Draft from the adjusted array and replaces it
    for (var i = 0; i < fullArray.length; i++) {
    	updatedList += "\n" + fullArray[i].name + ", " + fullArray[i].timesCalled;
    }
    
    
    let updatedText = title + "\n" + chosenWordsList + "\n" + updatedList
    
    
    draft.content = updatedText;
    draft.update();

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.